lastaflute / lasta-di

DI Container for LastaFlute, forked from Seasar as Java8
Apache License 2.0
9 stars 1 forks source link

is this need modify if (exp.length() < 9) { #24

Closed 15738519635 closed 5 months ago

15738519635 commented 6 years ago

protected Object resolveSimpleNumber(String exp, Map<String, ? extends Object> contextMap, LaContainer container, Class<?> resultType) { if (LdiStringUtil.isNumber(exp)) { if (exp.length() > 9) { return Integer.valueOf(exp); } else { return Long.valueOf(exp); } } return null; }

Caused by: java.lang.NumberFormatException: For input string: "5242880000" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_181] at java.lang.Integer.parseInt(Integer.java:583) ~[?:1.8.0_181] at java.lang.Integer.valueOf(Integer.java:766) ~[?:1.8.0_181] at org.lastaflute.di.core.expression.dwarf.SimpleExpressionPlainHook.resolveSimpleNumber(SimpleExpressionPlainHook.java:112) ~[lasta-di-0.7.6.jar:?]

jflute commented 6 years ago

Thank you for your feedback.

Certainly the if-statement of method was wrong. So I fixed it just now: (switch Integer and Long)

if (exp.length() > 9) {
    return Long.valueOf(exp);
} else {
    return Integer.valueOf(exp);
}

And I wrote unit test:

    public void test_resolveSimpleNumber_basic() {
        // ## Arrange ##
        SimpleExpressionPlainHook hook = new SimpleExpressionPlainHook();
        Map<String, ? extends Object> contextMap = new HashMap<>();

        // ## Act ##
        // ## Assert ##
        assertEquals(1, hook.resolveSimpleNumber("1", contextMap, createContainer(), Object.class));
        assertEquals(123, hook.resolveSimpleNumber("123", contextMap, createContainer(), Object.class));
        assertEquals(12345678, hook.resolveSimpleNumber("12345678", contextMap, createContainer(), Object.class));
        assertEquals(123456789, hook.resolveSimpleNumber("123456789", contextMap, createContainer(), Object.class));
        assertEquals(1234567890L, hook.resolveSimpleNumber("1234567890", contextMap, createContainer(), Object.class));
        assertEquals(2222222222L, hook.resolveSimpleNumber("2222222222", contextMap, createContainer(), Object.class));
        assertEquals(12345678901L, hook.resolveSimpleNumber("12345678901", contextMap, createContainer(), Object.class));
        assertEquals(99999999999L, hook.resolveSimpleNumber("99999999999", contextMap, createContainer(), Object.class));
    }

And I deployed Lasta Di-0.7.9-RC1. Please use this version for now.

...

While, the if-statement may be unnecessary, I'm thinking it. But simple fix first.