• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class names & loading: Java 5 vs Java 6

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like variants of this little program are popular on the web:



This works under Java 5 but throws an exception under Java 6. From what I can tell, the loadClass() method in Java 6 strictly enforces a "binary string" which not what is returned by the getName() method for an array.

Can anyone comment on this? It seems to have an impact on several open-source projects. I can't tell if this is an anticipated "tightening" of Java or a bug in the current Java 6 release. I've searched the web; there are references to the problem but no one is talking about the change per se.

thanks,
Mike
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the 1.5 javadocs for Class.getName, it states that getName returns the binary string (which is required for ClassLoader.loadClass) only for objects that are not arrays or primitives. For primitives the issue of class loading is moot, but it would not have occurred to me that the result of getName for an array can be used to load the component type of the array.

It should be easy to extract a usable name from the representation returned by getName, though.
 
M Easter
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess my question is: why the change now in Java 6?

i.e. is this considered a correction or a bug

See http://tinyurl.com/2x6gc8 (implies it is a bug)

thanks,
Mike
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by M Easter:
I guess my question is: why the change now in Java 6?

i.e. is this considered a correction or a bug

See http://tinyurl.com/2x6gc8 (implies it is a bug)

thanks,
Mike


It doesn't just imply, it states it is a bug.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That report does state it's a bug, but see also commentary here. Sounds like the preferred solution here is to simply use Class.forName() instead.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic