Maven编译器插件错误:无法访问枚举(错误签名,坏类)

Sem*_*lov 3 java enums javac maven

我正在使用maven-compiler-plugin:2.3.2,每次我ContentType在导入中有枚举()的类中进行更改时,我需要制作clean,否则它会给我:

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)
...
Run Code Online (Sandbox Code Playgroud)

ContentType是enum这样的:

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;
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

UPD1,项目结构:

        /wp2
             /core
                  /cpe
                     /widget
                           /ContentManager.java
                  /cdr
                     /entities
                           /ContentType.java
Run Code Online (Sandbox Code Playgroud)

UPD 2:

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

UPD 3:现代编译器也将显示bad classbad signature错误

Sem*_*lov 11

我终于找到了答案

错误发生在costructor中:

ContentType(@NotNull String title...

枚举中的构造函数不能包含注释,因为它javac是错误的.Javac为enum构造函数存储了错误的签名(你写的那个,而不是实际使用的那个 - 我记得它有两个额外的参数).在javac验证签名时,它会看到带注释的参数,在我的情况下,这是第一个参数.但是在实际签名中(String name, int ordinal, String title, CoreType coreType, boolean hasJad, String[] searchKeywords两个第一个参数由枚举 - >枚举翻译添加)title只是第三个参数,第一个参数name没有注释的,而javac认为类是不正确的.

tl; dr从构造函数中删除注释,javac是错误的