• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What changed in 1.5 to cause this?

 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it that in 1.3 and 1.4 final variables that are copied to an inner class are copied after initialization but in 1.5 it suddenly moved to before initialization? This came up as a result of this thread and I'm curious to know if anyone has any ideas. I've found the Sun forums have far more arrogance than they do actual knowledge and most of the intelligent posters are from Javaranch anyway so I'm asking here.

Compiled in 1.4:



Compiled in 1.5:



EDIT: Disabled smilies.
[ December 15, 2005: Message edited by: Ken Blair ]
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have any actual knowledge about that. I looked at the "what's new in Java 5" documents and couldn't find the word "final". Perhaps it's a bug fix? I couldn't find it in the bug database (my search for "final inner" returned about 10,000 results) but anyway, it certainly sounds like an improvement to me. I remember struggling against that problem back in Java 1.3 days and having to do some horrible workaround (as I classified it then).
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could this have something to do with JSR 133, Fixing the Java Memory Model?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it definitely sounds like a JSR-133 thing. One of the major concerns there was ensuring that there was no way for some threads to observe final fields changing their values, which could occasionally happen in earlier Java versions. This is achieved by making sure those fields are initialized before any reference to the constructed oject is allowed to escape for use or abuse by any threads other than the one performing construction. Bill Pugh's page has a nice JSR-133 FAQ covering this and other issues.
[ December 15, 2005: Message edited by: Jim Yingst ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic