Running on Java 24-ea+24-2960 (Preview)
Home of The JavaSpecialists' Newsletter

062bFollow-Up and Happy New Year!

Author: Dr. Heinz M. KabutzDate: 2002-12-31Java Version: 1.4Category: Language
 

Abstract: Java 1.4 changed inner classes slighty to set the link to the outer object prior to calling super(). This avoids some hard to explain NullPointerExceptions.

 

First of all, I wish you all the best for the year 2003!

Two of our readers, Dimitris Andreou from Greece and another by the name of Snow, pointed out that in JDK 1.4 the NullPointerException has been fixed. Have a look at Sun's website. Try compile the following class with the -target 1.4 option:

public class NestedBug3 {
  private Integer wings = new Integer(2);
  public NestedBug3() {
    new ComplexBug();
  }
  private class ComplexBug extends Insect {
    ComplexBug() {
      System.out.println("Inside ComplexBug Constructor");
    }
    public void printDetails() {
      System.out.println(wings);
    }
  }
  public static void main(String[] arguments) {
    new NestedBug3();
  }
}

When you compile this with -target 1.4 you will only be able to run it with a JVM 1.4 and later. Here is the output:

Inside Insect() Constructor
2
Inside ComplexBug Constructor

What happens in the inner class? Let's have a quick look:

jad -noinner NestedBug3$ComplexBug.class

class NestedBug3$ComplexBug extends Insect {
  NestedBug3$ComplexBug(NestedBug3 nestedbug3) {
    this$0 = nestedbug3;
    super();
    System.out.println("Inside ComplexBug Constructor");      
  }
  public void printDetails() {
    System.out.println(NestedBug3.access$000(this$0));
  }
  private final NestedBug3 this$0; /* synthetic field */
}

You can seen that the assignment of this$0 and the call to super() have been swapped around.

In case you were wondering where to get hold of JAD, I wrote to the author and he told me to tell you to look at JAD. I want to hereby publicly thank Pavel Kuznetsov for making this great tool freely available. I have learnt more from this tool than from any other Java tool.

In case you were wondering why I am spending my New Year's Party writing a newsletter, I just want to get this done quickly so that I can put the follow-up into the 2002 folder ;-)

Heinz

 

Comments

We are always happy to receive comments from our readers. Feel free to send me a comment via email or discuss the newsletter in our JavaSpecialists Slack Channel (Get an invite here)

When you load these comments, you'll be connected to Disqus. Privacy Statement.

Related Articles

Browse the Newsletter Archive

About the Author

Heinz Kabutz Java Conference Speaker

Java Champion, author of the Javaspecialists Newsletter, conference speaking regular... About Heinz

Superpack '23

Superpack '23 Our entire Java Specialists Training in one huge bundle more...

Free Java Book

Dynamic Proxies in Java Book
Java Training

We deliver relevant courses, by top Java developers to produce more resourceful and efficient programmers within their organisations.

Java Consulting

We can help make your Java application run faster and trouble-shoot concurrency and performance bugs...