ocpsoft / prettytime

Social Style Date and Time Formatting for Java
http://ocpsoft.org/prettytime/
Apache License 2.0
1.29k stars 253 forks source link

Proguard renaming of TimeUnit classes can lead to MissingResourceException: Can't find resource for bundle org.ocpsoft.prettytime.i18n.Resources, key ePattern #222

Open kevinslashslash opened 3 years ago

kevinslashslash commented 3 years ago

The bundled proguard rules only keep org.ocpsoft.prettytime.i18n but some ResourceBundle classes rely on TimeUnit.getClass().getSimpleName() which are in org.ocpsoft.prettytime.units and thus allowed to be renamed by proguard.

For example https://github.com/ocpsoft/prettytime/blob/3c2206d5b909b33354f9c09a8053a08b5ac93954/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_de.java#L133

Solutions I can think of are Refactor code to not use TimeUnit.getClass().getSimpleName(), it looks like ResourcesTimeUnit.getResourceKeyPrefix() is appropriate but it's not on TimeUnit directly Update proguard rules to keepnames for org.ocpsoft.prettytime.units, this is easiest to do but feels less than idea. It also slightly feels like it's covering up a deeper problem.

kevinslashslash commented 3 years ago

Relevant stack trace

java.util.MissingResourceException: Can't find resource for bundle org.ocpsoft.prettytime.i18n.Resources, key ePattern
        at java.util.ResourceBundle.getObject(ResourceBundle.java:445)
        at java.util.ResourceBundle.getObject(ResourceBundle.java:439)
        at java.util.ResourceBundle.getString(ResourceBundle.java:402)
        at org.ocpsoft.prettytime.i18n.Resources_de$DeTimeFormat.<init>(Resources_de:141)
        at org.ocpsoft.prettytime.i18n.Resources_de.getFormatFor(Resources_de:133)
        at org.ocpsoft.prettytime.impl.ResourcesTimeFormat.setLocale(ResourcesTimeFormat:52)
        at org.ocpsoft.prettytime.impl.ResourcesTimeFormat.setLocale(ResourcesTimeFormat:15)
        at org.ocpsoft.prettytime.PrettyTime.registerUnit(PrettyTime:1473)
        at org.ocpsoft.prettytime.PrettyTime.addUnit(PrettyTime:1613)
        at org.ocpsoft.prettytime.PrettyTime.initTimeUnits(PrettyTime:1597)
        at org.ocpsoft.prettytime.PrettyTime.<init>(PrettyTime:98)
        at org.ocpsoft.prettytime.PrettyTime.<init>(PrettyTime:86)
Mrjpjay commented 2 years ago

Same issue

lincolnthree commented 2 years ago

Happy to accept a PR for these issues. Thanks!