Javac bug, Eclipse innocent, bug in static imports

I had an issue compiling some java classes. Javac failed, Eclipse's compiler worked. The issue is described here.
I was blaming Eclipse, I was blaming java6's endorsing. I was thinking it was due to JAXB.

It comes out they all were innocent.

Here's my code:

package f;

 

import static f.ProblematicClass.E1.E2.VALUE;

 

import javax.annotation.Resource;

 

public class ProblematicClass {

 

    @Resource

    public static enum E1 {

        F(VALUE);

 

        private E1( E2
requiredBankAccounts ) {

        }

 

        public static enum E2 {

            VALUE;

        }

    }

}

The result with javac is:

>javac f\ProblematicClass.java

f\ProblematicClass.java:9: cannot find symbol
symbol  : class Resource
location: class f.CorrectClass1
        @Resource
         ^
1 error

After some research I think I simplified the problem:
(If I continue to simplify it would still fail to compile but at some
point it would start to compile which yesterday drove me crazy.
This is the most simplistic case that consistently fails to compile)

package f;

 

import static f.ProblematicClass.E1.VALUE;

import
javax.annotation.Resource;

 

public class ProblematicClass {

 

      @Resource

      public static enum E1 {

            VALUE;

      }

}

All of these changes fix the compilation error (from javac):

...

// Reverse the order of imports

import
javax.annotation.Resource;

import static f.ProblematicClass.E1.VALUE;

...

or

...
      // Use the FQN of the annotation

      @javax.annotation.Resource

      public static enum E1 {

            VALUE;

      }

...

This all makes me think that the static import fails the next one only if the next one is an annotation (I've tried with a java.util.Collection - it compiled).
I have tried this with jdk6u3 and jdk6u10.
I don't have jdk 1.5. Can someone test it on jdk 1.5?

Update: GRRRRRRRRRRRRRR, Somebody found it before me:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6391197
It was reported on 27th of June, 2006 :'(

Here's what they say:

Workarounds:
1) switching the order of the import statements works (although they often get changed back by our development tools).
2) Commenting out the static import statements, then compiling, then putting the import statements back and
compiling again with the old classes still there also works. This means that the compiler errors happen at the strangest
of times
, and in large programs it can be very difficult to work out how to workaround the problems.

One thought on “Javac bug, Eclipse innocent, bug in static imports”

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.