Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JaTimeFormat class can't get the unit name for a anonymous TimeUnit class. #155

Closed
chang-chao opened this issue Oct 12, 2017 · 1 comment

Comments

@chang-chao
Copy link

chang-chao commented Oct 12, 2017

Code snippet to reproduce the failure.

    private static final PrettyTime prettyTime = new PrettyTime();
    static {
        prettyTime.removeUnit(JustNow.class);
        ResourcesTimeUnit justNow = new ResourcesTimeUnit(Locale.JAPAN) {
            {
                setMaxQuantity(10000);
            }
            @Override
            protected String getResourceKeyPrefix() {
                return "JustNow";
            }
        };
        prettyTime.registerUnit(justNow, new ResourcesTimeFormat(justNow));
    }

It will fail with the following exception:

Exception in thread "main" java.util.MissingResourceException: Can't find resource for bundle org.ocpsoft.prettytime.i18n.Resources, key Pattern
	at java.util.ResourceBundle.getObject(ResourceBundle.java:450)
	at java.util.ResourceBundle.getObject(ResourceBundle.java:444)
	at java.util.ResourceBundle.getString(ResourceBundle.java:407)
	at org.ocpsoft.prettytime.i18n.Resources_ja$JaTimeFormat.(Resources_ja.java:148)
	at org.ocpsoft.prettytime.i18n.Resources_ja.getFormatFor(Resources_ja.java:117)
	at org.ocpsoft.prettytime.impl.ResourcesTimeFormat.setLocale(ResourcesTimeFormat.java:34)
	at org.ocpsoft.prettytime.impl.ResourcesTimeFormat.setLocale(ResourcesTimeFormat.java:16)
	at org.ocpsoft.prettytime.PrettyTime.registerUnit(PrettyTime.java:472)

this is because the getUnitName(TimeUnit) method of JaTimeFormat class cannot properly get the unit name in case of anonymous TimeUnit class(An empty string is returned).

        private String getUnitName(TimeUnit unit) {
            return unit.getClass().getSimpleName();
        }

This issule is related to lagom/online-auction-java#161

lincolnthree added a commit that referenced this issue Dec 19, 2020
@lincolnthree
Copy link
Member

Thanks for the issue! This should be resolved in version 5 since we've overhauled the TimeUnit registration API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants