struts2 ognl 中令人讨厌的 java.lang.NumberFormatException

发布于 2024-09-26 22:06:41 字数 2137 浏览 7 评论 0原文

我遇到了这个令人讨厌的异常,问题是我无法控制获取字符串,因为它是由第三方应用程序完成的。显然,该数字太长,无法解析为 int...

java.lang.NumberFormatException: For input string: "1286579871769"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:461)
        at java.lang.Integer.valueOf(Integer.java:528)
        at ognl.OgnlParserTokenManager.makeInt(OgnlParserTokenManager.java:63)
        at ognl.OgnlParserTokenManager.TokenLexicalActions(OgnlParserTokenManager.java:1624)
        at ognl.OgnlParserTokenManager.getNextToken(OgnlParserTokenManager.java:1498)
        at ognl.OgnlParser.jj_ntk(OgnlParser.java:3099)
        at ognl.OgnlParser.unaryExpression(OgnlParser.java:1079)
        at ognl.OgnlParser.multiplicativeExpression(OgnlParser.java:971)
        at ognl.OgnlParser.additiveExpression(OgnlParser.java:894)
        at ognl.OgnlParser.shiftExpression(OgnlParser.java:750)
        at ognl.OgnlParser.relationalExpression(OgnlParser.java:508)
        at ognl.OgnlParser.equalityExpression(OgnlParser.java:405)
        at ognl.OgnlParser.andExpression(OgnlParser.java:352)
        at ognl.OgnlParser.exclusiveOrExpression(OgnlParser.java:299)
        at ognl.OgnlParser.inclusiveOrExpression(OgnlParser.java:246)
        at ognl.OgnlParser.logicalAndExpression(OgnlParser.java:193)

struts2 snippet:

<package name="ajax" namespace="/ajax" extends="default">

        <default-interceptor-ref name="ajaxStack"/>

        <action name="**">
            <result>/WEB-INF/ajax/{1}.jsp</result>
        </action>

    </package>

并且拦截器:

<interceptor-stack name="ajaxStack">                        
                <interceptor-ref name="checkSession" />
                <interceptor-ref name="checkAjax" />    
                <interceptor-ref name="defaultStack" />                                 
            </interceptor-stack>

checkAjax 只是确保用户已登录并且 checkSession 存储会话参数在线程本地中。

I'm getting this nasty exception, the problem is that I cannot control the get string since it's done by a 3rd party app. Apparently the number is too long to be parsed as int...

java.lang.NumberFormatException: For input string: "1286579871769"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:461)
        at java.lang.Integer.valueOf(Integer.java:528)
        at ognl.OgnlParserTokenManager.makeInt(OgnlParserTokenManager.java:63)
        at ognl.OgnlParserTokenManager.TokenLexicalActions(OgnlParserTokenManager.java:1624)
        at ognl.OgnlParserTokenManager.getNextToken(OgnlParserTokenManager.java:1498)
        at ognl.OgnlParser.jj_ntk(OgnlParser.java:3099)
        at ognl.OgnlParser.unaryExpression(OgnlParser.java:1079)
        at ognl.OgnlParser.multiplicativeExpression(OgnlParser.java:971)
        at ognl.OgnlParser.additiveExpression(OgnlParser.java:894)
        at ognl.OgnlParser.shiftExpression(OgnlParser.java:750)
        at ognl.OgnlParser.relationalExpression(OgnlParser.java:508)
        at ognl.OgnlParser.equalityExpression(OgnlParser.java:405)
        at ognl.OgnlParser.andExpression(OgnlParser.java:352)
        at ognl.OgnlParser.exclusiveOrExpression(OgnlParser.java:299)
        at ognl.OgnlParser.inclusiveOrExpression(OgnlParser.java:246)
        at ognl.OgnlParser.logicalAndExpression(OgnlParser.java:193)

struts2 snippet:

<package name="ajax" namespace="/ajax" extends="default">

        <default-interceptor-ref name="ajaxStack"/>

        <action name="**">
            <result>/WEB-INF/ajax/{1}.jsp</result>
        </action>

    </package>

and the interceptor:

<interceptor-stack name="ajaxStack">                        
                <interceptor-ref name="checkSession" />
                <interceptor-ref name="checkAjax" />    
                <interceptor-ref name="defaultStack" />                                 
            </interceptor-stack>

checkAjax just makes sure the user is logged in and checkSession stores a session param in a threadlocal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2024-10-03 22:06:41

问题不在于 OGNL 解析器,而在于 Integer.parseInt() 方法。当我们向 Integer.parseInt 方法输入一个 String 时,编译时不会检测到该 String 的数值是否是范围内的数字。以下代码将显示编译时错误:

Integer y = new Integer(3223232320); 

但以下代码将引发运行时异常:

Integer y = new Integer("3223232320");

The issue is not with OGNL parser, it's the Integer.parseInt() method. When we input a String to the Integer.parseInt method, it is not detected at compile time if the numeric value of the String is a number in range. The following code will show a compile time error:

Integer y = new Integer(3223232320); 

But the following will throw a runtime exception:

Integer y = new Integer("3223232320");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文