3

I am using maven-compiler-plugin:2.3.2 and every time I make changes in classes which have an enum (ContentType) in imports, I need to make clean, otherwise it gives me:

ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project wp2: Compilation failure
[ERROR] /home/semyon/development/.../ContentManager.java:[15,46] error: cannot access ContentType
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project wp2: Compilation failure
/home/semyon/development/.../ContentManager.java:[15,46] error: cannot access ContentType

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:364)
...

ContentType is enum and looks like this:

import org.jetbrains.annotations.NotNull;

public enum ContentType {

    ...; 

    private final String title;

    private final boolean hasJad;

    private final CoreType coreType;

    private final String[] searchKeywords;



    ContentType(@NotNull String title, CoreType coreType, boolean hasJad, String[] searchKeywords) {
        this.title = title;
        this.coreType = coreType;

        this.hasJad = hasJad;
        this.searchKeywords = searchKeywords;
    }

    @NotNull
    public String getTitle() {
         return title;
    }

    @NotNull
    public String getName() {
        return name();
    }

    @NotNull
    public CoreType getCoreType() {
        return coreType;
    }

    public enum CoreType {

         ...;

        private String title;

        CoreType(String title) {
            this.title = title;
        }

        public String getTitle() {
            return title;
        }

    }
}

UPD1, project structure:

        /wp2
             /core
                  /cpe
                     /widget
                           /ContentManager.java
                  /cdr
                     /entities
                           /ContentType.java

UPD 2:

ContentManager.java:[15,46] is import wp2.core.cdr.entities.ContentType;

UPD 3: Modern compiler will show bad class and bad signature errors as well

13
  • Post your pom.xml and show us your directory structure.
    – carlspring
    Commented Jan 26, 2015 at 14:56
  • @carlspring pom is WAY too large to post it (~4000 lines), so maybe you can tell me what is important? Commented Jan 26, 2015 at 14:58
  • just post it on pastebin or on gist
    – Mysterion
    Commented Jan 26, 2015 at 15:00
  • 1
    i'm interested in ContentManager.java:[15,46] that file as well
    – Mysterion
    Commented Jan 26, 2015 at 15:02
  • 2
    @Mysterion I was able to finally find out the answer, I posted it Commented Jan 28, 2015 at 11:20

2 Answers 2

13

I finally found an answer

The error is in the costructor:

ContentType(@NotNull String title...

Constructors in enum must not have annotations in it, as javac is bugged. Javac stores incorrect signature for enum constructor (the one you writes, and not the one actually is used - it has two additional params as I recall). When javac verifies the signature it sees annotated parameter and in my case that was the first parameter. BUT in the actual signature (String name, int ordinal, String title, CoreType coreType, boolean hasJad, String[] searchKeywords, two first params are added by enum -> Enum translation) title is only third parameter and first parameter is name which is not annotated and javac thinks that class is incorrect.

tl;dr remove annotation from constructor, javac is buggy

2
  • Which version of Java is that? Does it still happen with Java 8? Note: You can compile code for a Java 6 VM / runtime with Java 8. Commented Jan 28, 2015 at 12:21
  • I compiled with both 6 and 7 java, didn't try with 8 (I suppose the problem persists as this bug remains unresolved. Commented Jan 28, 2015 at 12:58
1

Maybe a bug in the code which tries to determine which classes need to be compiled after a change.

Try the latest version of the Maven compiler plugin. The version number is on the page behind the link, in the header on the right, below the Maven logo (3.2 at the time of writing).

6
  • With version 3.2 it simply recompiles all classes even if only one class was changed. Commented Jan 27, 2015 at 14:29
  • That might be a new bug but it solves your issue. As far as I remember, the "recompile the minimum set of files after a change" is still an experimental feature. Commented Jan 27, 2015 at 16:18
  • That explains everything. I will try building and running maven in debug mode to see what exactly happens in MojoExecutor and why it can't access the class. Commented Jan 28, 2015 at 8:11
  • The exception is thrown from javac, so I don't think I can do much there:( Commented Jan 28, 2015 at 9:41
  • The question is why doesn't the Maven compiler plugin notice it has to recompile the enum as well. But I don't know how to debug the code which determines which files changed and what depends on those files. Commented Jan 28, 2015 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.