3 Replies Latest reply on May 1, 2013 10:23 PM by dwightd

    ArrayELResolver's handling of primitive arrays

    Oran Kelly Newbie

      I'm trying to understand whether the implementation of javax.el.ArrayELResolver or my application's (indirect) use of it is causing me problems.

       

      I'm basing my analysis on the source available at https://source.jboss.org/browse/JBossWeb/trunk/java/javax/el/ArrayELResolver.java?hb=true  Specifically, the setValue method starting at line 241.

       

      My application is trying to set the values of a primitive boolean array using checkboxes. I'm currently hitting the ClassCastException thrown at line 257 of ArrayELResolver when I submit a form. In trying to understand the ArrayELResolver code, I am struggling to see how it could  work for primitive array types.

       

      Take the following invocation of setValue:

       

      setValue(elContext, new boolean[2], Integer.valueOf(0), true);
      

       

      This will cause "type" to be assigned java.lang.Boolean.TYPE (line 255). Autoboxing will have wrapped the "true" value of val into Boolean.TRUE, so val.getClass() will return java.lang.Boolean on line 256.

       

      Boolean is not assignable from Boolean.TYPE (nor is Boolean.TYPE assignable from Boolean) so the if statement at line 256 cannot pass successfully and the ClassNotFoundException is thrown. It appears to me that this code, as it stands, cannot work for primitive array types.

       

      My question, then, is am I misusing some part of the JSF framework that is causing this, or is this a bug in the implementation of ArrayELResolver?

        • 1. Re: ArrayELResolver's handling of primitive arrays
          Jean-Frederic Clere Master

          The el code of jbossweb comes from the tomcat one there aren't complains (yet) for that. So I would say you miss some.

          • 2. Re: ArrayELResolver's handling of primitive arrays
            Oran Kelly Newbie

            Perhaps. But the code as it is cannot work for primitive arrays. So the question becomes: is this by design and is it invalid to attempt to use a primitive array in the first place, or is this simply a bug that no one has encountered because non-primitive arrays is the most common use-case.

            • 3. Re: ArrayELResolver's handling of primitive arrays
              dwightd Newbie

              FWIW, I just ran into this problem running under Tomcat 6.0.32 and 6.0.36, but the same application works fine in Tomcat 6.0.20.  So it is likely a change in Tomcat's ArrayElResolver that's causing the problem.  Partial stack:

               

              Caused by: java.lang.ClassCastException: Unable to add an object of type [java.lang.Boolean] to an array of objects of type [boolean]

                      at javax.el.ArrayELResolver.setValue(ArrayELResolver.java:94)

                      at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:69)

                      at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:237)

                      at org.apache.el.parser.AstValue.setValue(AstValue.java:158)

               

              There's a similar issue reported on the PrimeFaces forum http://forum.primefaces.org/viewtopic.php?f=3&t=24790 where the stack trace indicates they're running under Tomcat, but no version info was given.

               

              I've changed our code to use Boolean[] instead of boolean[], and now it works.  A bit more expensive, but in our case the code isn't exercised that often, so I can live with it.