Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Enclosing class instance availability during inner class initialization

Thread view: 
Stanimir Stamenkov - 13 Jul 2006 13:48 GMT
I've found couple of threads [1] discussing the exact same problem, but
I've wondered if there are some normative references governing the
change in the behavior I'm seeing between classes compiled with -target
1.4 and prior versions?

If I compile the following example with -target 1.4 and run it, I don't
get error, but If I compile it with no -target specified (or version <
1.4, using J2SDK 1.4.2) I get NullPointerException because of the
"missing" EnclosingInstanceTest instance at the given time. When I
compile with JDK 1.5 I don't get error because the default target seems
to be >= 1.4.

-----EnclosingInstanceTest.java
public class EnclosingInstanceTest {

   public static void main(String[] args) {
       EnclosingInstanceTest obj = new EnclosingInstanceTest();
       System.out.println("Start...");
       obj.doTest();
   }

   void doTest() {
       Whatever ever = new Whatever() {
           /* init */ {
               System.out.println("(2) Enclosing instance: "
                                  + EnclosingInstanceTest.this);
           }
           void doSomething() {
               System.out.println("(*) Enclosing instance: "
                                  + EnclosingInstanceTest.this);
               testInstance();
           }
       };
       ever.doSomething();
   }

   void testInstance() {
       System.out.println("O.k.");
   }

}

abstract class Whatever {

   Whatever() {
       System.out.println("(1) Super class init");
       // XXX: Uncomment the following line to test
       doSomething();
   }

   abstract void doSomething();

}
-----EnclosingInstanceTest.java--

[1] NullPointerException accessing instance member of enclosing
instance
<http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/81
eeb5e4e0d53a33/3aafa2d47d87780a
>,
   Getting a null "this"
<http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/dd
32223ae8a25867/c2c452392f0c7d70
>

Signature

Stanimir

Thomas Hawtin - 13 Jul 2006 14:46 GMT
> I've found couple of threads [1] discussing the exact same problem, but
> I've wondered if there are some normative references governing the
> change in the behavior I'm seeing between classes compiled with -target
> 1.4 and prior versions?

The URL leading to the information should be...

http://java.sun.com/j2se/1.4/compatibility.html

...but Sun have f.cked up, so it doesn't.

Relevant bugs include:

"* Initialization of up-level links, immediately after super(), occurs
too late."
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4030374

"VM throws an error "java.lang.VerifyError" (-target 1.4 versus inner cls)"
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4416605

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Chris Uppal - 13 Jul 2006 16:09 GMT
> I've found couple of threads [1] discussing the exact same problem, but
> I've wondered if there are some normative references governing the
> change in the behavior I'm seeing between classes compiled with -target
> 1.4 and prior versions?

Nothing normative that I know of.  I seem to remember there was an entry in the
change notes, but can't find it now.

There are several bug parade entries, one is
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4030374

A completely different kind of authority is the source, and the 1.5 source
there's a file

   <jrl>/j2se/src/share/classes/com/sun/tools/javac/jvm/Target.java

which contains a nice list of target-dependent behaviour changes for the
compiler.  I don't know how interesting that is to you.  I mention it here
principally so that I'll be able to find the file again myself ;-)

   -- chris
Stanimir Stamenkov - 14 Jul 2006 13:17 GMT
> A completely different kind of authority is the source, and the 1.5 source
> there's a file
>
>     <jrl>/j2se/src/share/classes/com/sun/tools/javac/jvm/Target.java

Where do you get that source file from (I haven't understood the <jrl>
part)? Searching in my JDK 1.5 installation "src.zip" I don't really
find it.

Signature

Thanks,
Stanimir

Stanimir Stamenkov - 14 Jul 2006 13:43 GMT
>> A completely different kind of authority is the source, and the 1.5 source
>> there's a file
[quoted text clipped - 4 lines]
> part)? Searching in my JDK 1.5 installation "src.zip" I don't really
> find it.

Sorry for asking the obvious (I've missed it): "the 1.5 source":

"J2SE 5.0 JDK Source Code"
<http://java.sun.com/javase/downloads/index.jsp>

Signature

Stanimir

Chris Uppal - 14 Jul 2006 14:13 GMT
> "J2SE 5.0 JDK Source Code"
> <http://java.sun.com/javase/downloads/index.jsp>

You beat me to it ;-)

But, seriously, I hope you read the license conditions carefully before
accepting them -- I would have warned you but you were too quick for me...

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.