EL does not coerce String to Integer in equals operation in EAP 7

Solution Unverified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7.x

Issue

EAP 7's EL equals operations work differently from EAP 6 one. EL does not coerce String to Integer in equals operation in EAP 7.

For example: put the following test.jsp in your web application (e.g. example.war)

<% request.setAttribute("testAttr", "01"); %>
${testAttr == 1}</br>
${param['foo'] == 1}<br>
${1 == param['foo']}<br>
${1 == (0+param['foo'])}<br>

Then, access the above JSP with the following curl command:

$ curl http://localhost:8080/example/test.jsp?foo=01

EAP 6's expected result:

true<br>
true<br>
true<br>
true<br>

EAP 7's actual result:

false<br>
false<br>
false<br>
true<br>

Resolution

This looks like a bug in EAP 7 EL implementation. This content is not included.JBEAP-18391 has been raised to improve the behavior and will be fixed in future releases (tentatively EAP 7.2 CP8 or later).

In the section 1.9.2 of Content from download.oracle.com is not included.EL 3.0 Specification, the ==,!= operators have the following step:

■ If A==B, apply operator
■ If A is null or B is null return false for == or eq, true for != or ne.
■ If A or B is BigDecimal, coerce both A and B to BigDecimal and then:
■ If operator is == or eq, return A.equals(B)
■ If operator is != or ne, return !A.equals(B)
■ If A or B is Float or Double coerce both A and B to Double, apply operator
■ If A or B is BigInteger, coerce both A and B to BigInteger and then:
■ If operator is == or eq, return A.equals(B)
■ If operator is != or ne, return !A.equals(B)
■ If A or B is Byte, Short, Character, Integer, or Long coerce both A and B to Long, apply operator
■ If A or B is Boolean coerce both A and B to Boolean, apply operator
■ If A or B is an enum, coerce both A and B to enum, apply operator
■ If A or B is String coerce both A and B to String, compare lexically
■ Otherwise if an error occurs while calling A.equals(B), error
■ Otherwise, apply operator to result of A.equals(B)

Note that the step "If A or B is Byte, Short, Character, Integer, or Long coerce both A and B to Long, apply operator" should happen earlier than the step coercion to String. So, it appears that EAP 7's behavior violates the spec.

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.