8 Replies Latest reply on Jan 11, 2008 4:37 PM by alesj

    JBMICROCONT-224

    alesj

      OK, this look pretty straight forward, except that I don't like where the code resides. :-)

      Doing this in ArrayInfoImpl.getType is where this is needed:

       if (annotatedElement == null)
       {
       try
       {
       annotatedElement = Class.forName(name, true, componentType.getType().getClassLoader());
       }
       catch (Throwable t)
       {
       throw new UndeclaredThrowableException(t);
       }
       }
       return (Class<? extends Object>)annotatedElement;
      

      But using Class.forName outside TypeInfoFactory (TIF) doesn't seem right.
      Should I introduce new method on TIF?
      If so, how to name it, params, ...

      Perhaps this?
      TypeInfo getTypeInfo(String name, boolean initialize, ClassLoader cl) throws ClassNotFoundException;
      


        • 1. Re: JBMICROCONT-224

          I'd just change all the uses of the classloader.loadClass() to be Class.forName()

          Actually resolve=false is the equalivent of ClassLoader.loadClass()

          e.g.

           private TypeInfo resolveComplexTypeInfo(ClassLoader cl, String name)
           throws ClassNotFoundException
           {
           if (cl == null)
           cl = Thread.currentThread().getContextClassLoader();
          
          - Class clazz = cl.loadClass(name);
          + Class<?> clazz = Class.forName(name, false, cl);
           return getTypeInfo(clazz);
           }
          


          • 2. Re: JBMICROCONT-224
            alesj

             

            "adrian@jboss.org" wrote:
            I'd just change all the uses of the classloader.loadClass() to be Class.forName()

            Actually resolve=false is the equivalent of ClassLoader.loadClass()

            Initialize, not resolve. :-)
             public static Class<?> forName(String name, boolean initialize,
             ClassLoader loader)
             throws ClassNotFoundException
            

            But in our case, as the JIRA (http://jira.jboss.com/jira/browse/JBMICROCONT-224) suggest (as you suggest :-)), initialize=true must be used.
            Which still calls for a new method. :-)

            • 3. Re: JBMICROCONT-224

               

              "alesj" wrote:
              "adrian@jboss.org" wrote:
              I'd just change all the uses of the classloader.loadClass() to be Class.forName()

              Actually resolve=false is the equivalent of ClassLoader.loadClass()

              Initialize, not resolve. :-)


              It's resolve. It means do you resolveClass() when you load the class. ;-)

              "alesj" wrote:

               public static Class<?> forName(String name, boolean initialize,
               ClassLoader loader)
               throws ClassNotFoundException
              

              But in our case, as the JIRA (http://jira.jboss.com/jira/browse/JBMICROCONT-224) suggest (as you suggest :-)), initialize=true must be used.
              Which still calls for a new method. :-)


              No. The parameter is false when you invoke loadClass() on the ClassLoader,
              see the javadoc.

              • 4. Re: JBMICROCONT-224
                alesj

                 

                "adrian@jboss.org" wrote:

                It's resolve. It means do you resolveClass() when you load the class. ;-)

                OK, I see what you mean now. :-)
                But I don't understand what has this got to do with Class.forName(name, true, classloader);

                • 5. Re: JBMICROCONT-224

                   

                  "alesj" wrote:
                  "adrian@jboss.org" wrote:

                  It's resolve. It means do you resolveClass() when you load the class. ;-)

                  OK, I see what you mean now. :-)
                  But I don't understand what has this got to do with Class.forName(name, true, classloader);


                  ? I've said it twice above.

                  The second parameter in Class.forName() is the same as resolve.
                  ClassLoader.loadClass() is the same as Class.forName(name, false, classLoader)
                  except it also loads array classes in JDK7+, they both did before.

                  initialize or resolve=true is a red herring. I just wrote true "at random" on the bug report
                  because the parameter needs a value.

                  • 6. Re: JBMICROCONT-224
                    alesj

                     

                    "adrian@jboss.org" wrote:

                    The second parameter in Class.forName() is the same as resolve.
                    ClassLoader.loadClass() is the same as Class.forName(name, false, classLoader)
                    except it also loads array classes in JDK7+, they both did before.

                    OK, that's what I thought.
                    Got confused somewhere along the way with that red herring true. ;-)
                    JDK7? Or 6, right?

                    "adrian@jboss.org" wrote:

                    is a red herring.

                    http://en.wikipedia.org/wiki/Red_herring :-)

                    • 7. Re: JBMICROCONT-224

                       

                      "alesj" wrote:

                      JDK7? Or 6, right?


                      Yes JDK6 is when it was changed in the Sun JDK.


                      • 8. Re: JBMICROCONT-224
                        alesj

                         

                        "adrian@jboss.org" wrote:
                        I'd just change all the uses of the classloader.loadClass() to be Class.forName()

                        Even in the classloader module?
                        - BaseClassLoaderDomain
                        - ClassLoaderToLoaderAdapter