permaculture playing cards*
The moose likes Java in General and the fly likes What changed in 1.5 to cause this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What changed in 1.5 to cause this?" Watch "What changed in 1.5 to cause this?" New topic
Author

What changed in 1.5 to cause this?

Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
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
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

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

Joined: Sep 16, 2005
Posts: 1780
Could this have something to do with JSR 133, Fixing the Java Memory Model?


There is no emoticon for what I am feeling!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
 
 
subject: What changed in 1.5 to cause this?