BUG: Oracle Java Compiler bug with anonymous inner classes in constructor

The following code compiles and runs just fine using 1.4.2_07, 1.5.0_07 and 1.6.0_beta2 when compiling and running from the command-line.
It does not run when compiling from JDeveloper 10.1.3.36.73 (which uses the ojc.jar).
When compiled from JDeveloper, the JRE (both the embedded one or the external 1.5.0_07 one) reports the following error:
java.lang.VerifyError: (class: com/ids/arithmeticexpr/Scanner, method: <init> signature: (Ljava/io/Reader;)V) Expecting to find object/array on
stack
Here's the code:
/** lexical analyzer for arithmetic expressions.
Fixes the lookahead problem for TT_EOL.
public class Scanner extends StreamTokenizer
/** kludge: pushes an anonymous Reader which inserts
a space after each newline.
public Scanner( Reader r )
super( new FilterReader( new BufferedReader( r ) )
protected boolean addSpace; // kludge to add space after \n
public int read() throws IOException
int ch = addSpace ? ' ' : in.read();
addSpace = ch == '\n';
return ch;
public static void main( String[] args )
Scanner scanner = new Scanner( new StringReader("1+2") ); // !!!
Removing the (implicit) reference to 'this' in the call to super() by passing an instance of a static inner class 'Kludge' instead of the anonymous subclass of FilterReader fixes the error. The code will then run even when compiled with ojc. There seems to be a bug in ojc concerning references to the partially constructed object (a bug which which is not present in the reference compilers.)
-- Sebastian

Thanks Sebastian, I filed a bug for OJC, and I'll look at the Javac bug. Either way, OJC should either give an error or create correct code.
Keimpe Bronkhorst
JDev Team

Similar Messages

  • Oracle Java Compiler 11g - JVM ERROR

    Hi Jdev Team,
    I have an issue to report,
    Sometimes when run a project and navigate through the pages, i get the following error message:
    Oracle Java Compiler 11g
    Unable to create an instance of the Java Virtual Machine
    Located at path:
    H:\jdevstudio1111\jdk\jre\bin\client\jvm.dll
    The only way to solve this is delete the settings of the Jdev and the Jdev from the PC, and install again, with the associated waste of time as consecuence. Please you can give a light to resolve this issue? Thanks
    Well i correct what i just said.
    The problem doesn´t fix, with the erase of the jdev program folder or settings folder in windows user docs and settings. What else i can do!?, out of ideas in here.
    Regards,
    Leo
    Message was edited by:
    LCJ

    Solution (workaround):
    Re: ADF table and filtering
    Pedja

  • Oracle java compiler

    Hi everyone,
    I just wanted to create a new Project Build-Script as I stumbled upon this Checkbox (for auto-generating my Script):
    "use oracle java compiler for javac task"
    Can anybody tell me where I find a list of features this compiler provides in comparison to my normal compiler. (I tried JDev, Google and here...)
    Are there any profits with using ADF / Business Components?
    Hay.

    Hay,
    If you are using JDev 10g - you need to use OCJ to get some of the profiling aspects; less of a reason to use OJC in 11g.
    John

  • Mysterious anonymous inner class in switch block

    public class MysteryFile {
      public enum Elements {
        WIND, EARTH, FIRE, WATER
      Elements el;
      public MysteryFile(Elements el) {
        this.el = el;
      public void whatIsItLike() {
        switch (el) {
          case WIND: System.out.println("A bit chilly sometimes"); break;
          case EARTH: System.out.println("Gets hands dirty."); break;
          case FIRE: System.out.println("Hot! skin melt"); break;
          case WATER: System.out.println("Cool! clean hands"); break;
          default: System.out.println("Don't know"); break;
      public static void main(String[] args) {
        MysteryFile anElement = new MysteryFile(Elements.FIRE);
        anElement.whatIsItLike();
    }When compiled in Netbeans or in the command line, generates an unexpected MysteryFile$1.class file. If the entire switch block is commented out and recompiled, it does not get generated. Where does this anonymous inner class come from?

    The MysteryFile$1 class looks something like this (javac 1.6.0_02):
    class MysteryFile$1 {
      static final int[] $SwitchMap$MysteryFile$Elements;
      static {
          // the line number (debug info) of this static initializer
          // is "switch (el)" line in MysteryFile.java
          $SwitchMap$MysteryFile$Elements =
                  new int[MysteryFile$Elements.values().length ];
          try {
              $SwitchMap$MysteryFile$Elements[
                      MysteryFile$Elements.WIND.ordinal() ] = 1;
          } catch (NoSuchFieldError e) {
              // fix stack?
          // repeat with EARTH(2), FIRE(3) and WATER(4)
    }... and the actual switch statement in 'MysteryFile' looks like so:
      //switch (el) {
      switch(MysteryFile$1.$SwitchMap$MysteryFile$Elements[
              this.el.ordinal() ])
      case 1:  // WIND
          break;
      case 2:  // EARTH
          break;
      case 3:  // FIRE
          break;
      case 4:  // WATER
          break;
      default:  // ...
      }I suppose this is necessary because the compiler can't guarantee that the runtime enum-constant-to-ordinal mapping will be identical to that at compile time (the API docs say it depends on the declaration order in the source code, which I think may change without breaking binary compatibility).
    PS MysteryFile$Elements.values() is a synthetic method that returns all enumeration constants in a MysteryFile$Elements array. Found this old related thread: [http://forum.java.sun.com/thread.jspa?threadID=617315]

  • Question on Anonymous Inner class !

    Can an Anonymous Inner class implement or extend any thing?
    I feel no .. if yes can anyone give an example please..

    An example: the anonymous inner class in u extends Thread.
    $ cat u.java
    class u {
    public static void main(String a[]) {
    Thread t = new Thread ( ) {
    public void run() {
    System.out.println(getClass().getName());
    t.start();
    $ javac u.java
    $ java u
    u$1
    $
    The same idea but with the Runnable interface (and not class)
    $ cat u.java
    class u {
    public static void main(String a[]) {
    Thread t = new Thread ( new Runnable ( ) {
    public void run() {
    System.out.println(getClass().getName());
    t.start();
    $ java u
    u$1

  • Trying to use super class's methods from an anonymous inner class

    Hi all,
    I have one class with some methods, and a second class which inherits from the first. The second class contains a method which starts up a thread, which is an anonymous inner class. Inside this inner class, I want to call a method from my first class. How can I do this?
    If I just call the method, it will use the second class's version of the method. However, if I use "super," it will try to find that method in the Thread class (it's own super class) and complain.
    Any suggestions?
    Code:
    public class TopClass
         public void doSomething(){
              // do something
    =============================
    public class LowerClass extends TopClass
         // overrides TopClass's doSomething.
         public void doSomething(){
              // do something
         public void testThread(){
              Thread t = new Thread(){
                   public void run(){
                        doSomething();               //fine
                        super.doSomething();          //WRONG: searches class Thread for doSomething...
              t.start();
    }

    Classes frequently call the un-overridden versions of methods from their superclasses. That's that the super keyword is for, if I'm not mistaken.You're not mistaken about the keyword, but you're not calling the superclass method from a subclass. Your anonymous inner class is not a subtype of TopLevel. It's a subtype of Thread.
    Here it is no different, except that I happen to be in a thread at the time.It's vastly different, since you're attempting to call the method from an unrelated class; i.e., Thread.
    I could also be in a button's action listener, for example. It seems natural to me that if I can do it in a method, I should be able to do it within an anonymous inner class which is inside a method.If you were in an button's action listener and needed to call a superclass' implementation of a method overridden in the button, I'd have the same questions about your design. It seems smelly to me.
    ~

  • Semi-Anonymous Inner Class?

    From API description of invokeLater method of SwingUtilities class:
    /* begin quote
    In the following example the invokeLater call queues the Runnable object doHelloWorld on the event dispatching thread and then prints a message.
    Runnable doHelloWorld = new Runnable() {
    public void run() {
    System.out.println("Hello World on " + Thread.currentThread());
    SwingUtilities.invokeLater(doHelloWorld);
    System.out.println("This might well be displayed before the other message.");
    */ end quote
    The interface class is named (doHelloWorld) so it's not really anonymous.
    But the class is not declared; there's no class keyword.
    Is there a formal name for this construction?
    It seems like a hybrid of named and anonymous implementation.
    I guess the ability to mix class declaration, instantiation, method declaration, etc in one statement is powerful but just hard for beginner to understand when to use.
    Sigh, three ways to do same thing. This 'hybrid' form is actually harder to understand than other ways.
    private class myRunnable implements Runnable {
    public void run() {
    System.out.println("Hello World on " + Thread.currentThread());
    myRunnable doHelloWorld = new myRunnable();
    OR
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    System.out.println("Hello World on " + Thread.currentThread());
    Thanks,
    Stanley.

    The interface class is named (doHelloWorld) so it's
    not really anonymous. No. There's a variable that points to an instance of that class, and the variable is named doHelloWorld. The class is anonymous.
    Is there a formal name for this construction?Anonymous inner class.

  • Question about anonymous inner class??

    Is there any error occurs,If a class declear & implement two anonymous inner classes ??

    public class TryItAndSee {
        void m() {
            Runnable x = new Runnable(){
                public void run() {
                    System.out.println("?");
            Runnable y = new Runnable(){
                public void run() {
                    System.out.println("!");
    }

  • Adapters vs anonymous inner class (please help)

    I am trying to clean up my code by using anonymous inner classes to handle some action events. My code looks like this but I get an error
    Button.addActionListener(new MyClass() {
    public void actionPerformed(ActionEvent e) {
    my_Button_actionPerformed(e);
    it says that it cant find MyClass, but I thought I dont need to define it becaue I am defining it here, isnt that the point of a anonymous inner class

    yourBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
    });(BTW: use code tags in posting!)

  • Cant complie "anonymous inner class" on JDK1.4

    public Enumeration enumerator()
    return new Enumeration()
    int currentItem = items.size() - 1;
    public boolean hasMoreElements() {
    return (currentItem >= 0);
    error: cant resolve symbol
    help me! thanx u very much

    Since Enumeration is an interface, the anonymous inner class needs to implement both functions.
    public Enumeration enumerator()
      return new Enumeration()
         int currentItem = items.size() - 1;
         public boolean hasMoreElements()
            return (currentItem >= 0);
         public Object nextElement()
            return items.elementAt(currentItem--);
    }I assume that items is a member field of the class containing this method. Since I don't know what it is , the elementAt is only a guess.

  • Anonymous Inner Class question

    How can I get "foof" to be echoed to the screen?
    class MyClass {
       void go() {
          Bar b = new Bar();
          b.doStuff(new Foo() {
             public void foof() {
                System.out.println("foof");
    interface Foo {
       void foof();
    class Bar {
       void doStuff(Foo f) {}
    public class TestWonder {
       public static void main (String... args) {
       new MyClass().go();
       //Why doesn't this print out "foof" to the screen? Nothing is echoed to the screen.
    }

    Sorry to be so thick, but I thought that the code did that already. Apparently it doesn't. In other words, how would the code invoke the override foof()? I should be clearer:
    I know if I change Bar's doStuff() to
    void doStuff(Foo f) {
    System.out.println("bar's dostuff");
    }then when go() is executed bar's dostuff will print out. But, what about the override in the anonymous inner class?
    Edited by: RonNYC2 on Feb 5, 2010 1:03 PM
    Edited by: RonNYC2 on Feb 5, 2010 1:05 PM

  • Ridiculous bug in oracle jdeveloper compiler ojc with jdk1.4

    With simple class:
    public class Test
    public Test()
    public String toString()
    return null;
    public static void main(String[] args) throws Exception
    Test test = new Test();
    System.out.println("ooo" + test);
    After compile it with ojc (ojc Test.java) and run it with jdk 1.4.1_01 (java Test), it throws
    java.lang.NullPointerException
    at java.lang.String.concat(String.java:1541)
    But it works ok if compile it with standard java compiler(javac).

    Hi,
    Thanks for reporting this. It's a bug. I've logged it as 2809860, and you can track this on metalink.oracle.com.
    Brian
    JDev Team

  • Bug in Oracle Java Compiler???

    Hello!
    I think I found a bug in OJC. Take a look in these files:
    ------ File MyInterface1.java -------
    public interface MyInterface1
    public void aMethod1();
    public void aMethod2();
    ------ File MyInterface2.java -------
    public interface MyInterface2 extends MyInterface1
    public void aMethod1(String s1);
    public void aMethod2(String s2);
    ------ File MyAbstractClass.java -------
    abstract public class MyAbstractClass implements MyInterface2
    public void aMethod1()
    ------ File MyImplClass.java -------
    public class MyImplClass extends MyAbstractClass
    public void aMethod2()
    public void aMethod1(String s)
    When compiling these files, the following error should be found:
    "javac MyImplClass.java
    MyImplClass.java:1: MyImplClass should be declared abstract; it does not define
    aMethod2(java.lang.String) in MyAbstractClass
    public class MyImplClass extends MyAbstractClass
    ^
    1 error"
    This is the error found by javac (J2SE 1.3), as expected.
    But when I compile using OJC 9.0.2.579 (JDeveloper 9.0.2.829) no error is found, and the compiler generates MyImplClass.class. This should not happen!!!
    Even if I implement aMethod2(String s) in MyImplClass, how can I trust that OJC is generating the bytecode, so that the method invocation is occuring correctly during runtime?
    I have a component library based on class hierarchy like the one in the example, and I would not like to modify it because of this possible bug in OJC.
    Thanks
    Gleber/Daniel/Augusto

    Gleber,
    As per current plans the 903 release is expected to be on OTN in the next 5-7 weeks. Feel free to ping me at [email protected] if this bug is preventing you from moving forward. I'll try to resolve your issue with a workaround.
    Regards,
    Arun

  • Error in compilation - Bug in the Oracle Java Compiler ? (10.1.3)

    I've the following situation :
    I've a class wich extends ViewObjectImpl,named ClViewObjectImpl, and another class, named RbViewObjectImpl wich extends ClViewObjectImpl.
    My classes have only a constructor with no parameters .
    Compiling with standard Oracle complier I get the following error
    Error: method $init$() in class oracle.jbo.server.RbViewObjectImpl cannot override method $init$() in class oracle.jbo.server.ClViewObjectImpl with weaker access privileges, was
    Compiling with javacc it compiles.
    Is it an bug ?
    Is there any workaround ?
    Tks
    Tullio

    Repost

  • Accessing member variable within an anonymous inner class

    I'm getting a compiler error with the following snippet which resides in a constructor (error below):
            final String fullNamesArr[] = new String[ lafsArr.length ];
            String lafNamesArr[] = new String[ lafsArr.length ];
            JMenuItem namesMenuItemArr[] = new JMenuItem[ lafsArr.length ];
            for ( int i = 0 ; i < lafsArr.length ; i++ )
                StringTokenizer tokenizer;
                fullNamesArr[ i ] = lafsArr[ i ].getClassName();
                tokenizer = new StringTokenizer( fullNamesArr[ i ] );
                while ( tokenizer.hasMoreTokens() )
                    lafNamesArr[ i ] = tokenizer.nextToken( "." );
                namesMenuItemArr[ i ] = new JMenuItem( lafNamesArr[ i ] );
                lafMenu.add( namesMenuItemArr[ i ] );
                namesMenuItemArr[ i ].addActionListener(new ActionListener()
                        public final void actionPerformed(final ActionEvent e)
                            String actionCommand = e.getActionCommand();
                            int iCount = 0;
                            for ( int index = 0 ; index < fullNamesArr.length ; index++ )
                                if ( fullNamesArr[ index ].contains( actionCommand ))
                                    iCount = index;
                                    break;
                            System.out.println( "Setting LAF to '" +
                                                fullNamesArr[ iCount ] + "'" );
                            try
                                UIManager.setLookAndFeel( fullNamesArr[ iCount ] );
                            catch ( UnsupportedLookAndFeelException ulafe )
                                System.out.println( fullNamesArr[ iCount ] +
                                                    " : Not a valid LAF class." );
                            catch ( ClassNotFoundException cnfe )
                                System.out.println( fullNamesArr[ iCount ] +
                                                    " : Class not found." );
                            catch ( InstantiationException ie )
                                System.out.println( fullNamesArr[ iCount ] +
                                                    " : Can't instantiate class." );
                            catch ( IllegalAccessException iae )
                                System.out.println( fullNamesArr[ iCount ] +
                                                    " : Illegal access." );
    DBBuilder.java:1280: cannot resolve symbol
    symbol : method contains (java.lang.String)
    location: class java.lang.String
    if ( fullNamesArr[ index ].contains( actionCommand ))
    ^
    1 error
    BUILD FAILED
    My question: Why can I access fullNamesArr in other spots in the anon-inner class,but not with the String.contains() method? BTW, the carrot is under the left bracket '['.
    TIA,
    Jeff

    My question: Why can I access fullNamesArr in other
    spots in the anon-inner class,but not with the
    String.contains() method? BTW, the carrot is under
    the left bracket '['.You're misinterpreting the message. The problem is not your variable fullNamesArr, but rather the method contains(java.lang.String). Since that method was only added in Java 5 (aka 1.5) you might look if you're compiling with JDK 1.4 or earlier.

Maybe you are looking for

  • How do you create a new Game center account for IOS 8.1?

    I really want to know how to create a Game center account on IOS 8.1. Can u please help me?

  • OS9 version of Outlook Express to Leopard version of Mail

    Hello, I have to help a friend migrate from an early 2000 iMac running OS9 to a current new iMac running Leopard (still to be purchased). According to MacTracker her old iMac does have Fire Wire so I imagine I should be able to hook up the two comput

  • XML attributes as a response

    My skills are rudimentary, I'm a new flex developer. I have done all of the tutorials and examples and I'm just struggling with using an XML attribute checking a response. I've written a simple flex 3 app to talk to Asterisk AJAM. I'm writing the log

  • 1 website and 2 mac

    Hi....I created a website with IWeb with my MacPro. I then bought a Macbook and I want to continue to work on my website with this new computer. How can I make the transition to my new computer. Do I have to redo my website from scratch with my new c

  • Is Photos using a lot of CPU?

    Photos is now using a lot of CPU. This is after it converted my iPhoto library. Is this normal? Is anyone else seeing this on their machine? Here's a screen shot with Photos hidden (not actively being used).