Stefan Seidel
Stefan Seidel

Reputation: 10577

Mojarra JSF 2.1 fails to call correct method after upgrade to JDK7

We're looking into switching our fairly big webapp (using Primefaces, Mojarra 2.1, Jetty) from Sun JDK6 + Jetty 6 to Oracle JDK7 + Jetty 9. Mostly this was painless, but it seems the method access is different on Java 7.

When having a class with the two methods

public Object getValue(int _index) {...}

and

public Object getValue(String _name) {...}

and using

#{myBean.getValue(index)}

would call the correct method (with int parameter) and return the correct value under Java 6. In Java 7, however, it would silently fail and not return/print out anything. When I change the method name and use the appropriate name in the JSF file, the access works as expected.

Why am I seeing this only on Java 7 and is there a way to restore the old behaviour (which, basically, worked like it does in Java code - the correct method is used based on the class(es) of the parameters)?

Upvotes: 0

Views: 173

Answers (1)

BalusC
BalusC

Reputation: 1108802

This is not specific to JSF/Mojarra, but to EL and reflection API. You'd have had exactly the same problem when using MyFaces, for example.

You were facing a bug in the EL implementation being used by Jetty. It does apparently not take method parameter types into account while finding a method (exactly like as how EL functions work). Buggy EL implementations will just loop over Class#getDeclaredMethods() and pick the first one matching the name and ignore the parameter types. As you can read in Class#getDeclaredMethods() javadoc,

... The elements in the array returned are not sorted and are not in any particular order. ...

the order is undefinied. Actually, under the covers, it's dependent on the JVM make/version. That at least explains the difference when switching the JVM.

I recommend to upgrade the EL implementation being used or to rename your method.

Upvotes: 1

Related Questions