0

We have a Java EE 6 JSF project running on JDK 7 and JBoss EAP 6.

We have a utily class around the message bundles where we have two methods with the same name, but different parameters and making use of varargs:

public void doSomething(String name) {..}
public void doSomething(String name, Object... params) {..} 

When using these methods within an EL expression in an XHTML page, we have the strange behaviour that the application produced a NPE in the customers test environment (Linux, JDK 7 Update 91), but not in ours (Windows, JDK 7 Update 80) and after digging a bit deeper it turned out, that it happenend within the invokeMethod(..) of JBoss EL API because of selecting the wrong method - the 2nd one was taken despite the fact that only 1 parameter was given within the EL expression.

We have yet to check what differs exactly between the two testing environments besides the mentioned above and of course it's easy to fix by renaming one of the methods - but has anyone experienced this behaviour and can tell me why it happens?

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96
  • varargs are optional, so calling the second method without any varargs is valid as well. The EL implementation just looks for a method that could handle the requested execution. Might be an issue with the ordering of the methods, but I would probably simply fix the one with varargs to work with no args as well and simply let the first call the second (and mark it deprecated). That way it doesn't matter which one of the 2 methods is called. – M. Deinum Dec 07 '15 at 11:50
  • @M.Deinum: Yes, I thought of this as well. Stil it is strange for me, that it only happens in one of the environments, the other calls the correct method. – Alexander Rühl Dec 07 '15 at 12:08
  • @AlexanderRühl Its actually nothing strange. Welcome to the world if behavior influenced by randomized order of execution. If you look at the code design you have now, its quite understandable that different implementations can lead to different results since it is a bit ambiguous. It can be the difference between EL resolvers sorting on number of method parameters or not. – Gimby Dec 07 '15 at 12:16

0 Answers0