java - Maven 编译器插件错误 : can't access enum (bad signature, bad class)

标签 java maven enums javac

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

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

    }
}

UPD1,项目结构:

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

更新 2:

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

更新 3: 现代编译器也会显示 bad classbad signature 错误

最佳答案

终于找到答案了

错误在构造函数中:

ContentType(@NotNull 字符串标题...

枚举中的构造函数中不能有注释,因为 javac 有问题。 Javac 为 enum 构造函数存储不正确的签名(您编写的签名,而不是实际使用的签名——我记得它有两个额外的参数)。 当 javac 验证签名时,它会看到 annotated 参数,在我的例子中是 first 参数。但是在actual 签名中(String name, int ordinal, String title, CoreType coreType, boolean hasJad, String[] searchKeywords,两个第一个参数由枚举添加 -> 枚举翻译)title只是第三个参数,第一个参数是name没有注释 并且 javac 认为类不正确。

tl;dr 从构造函数中删除注解,javac 有问题

关于java - Maven 编译器插件错误 : can't access enum (bad signature, bad class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28152412/

相关文章:

java 插件在 Android Studio 项目中工作,但在 Unity 中不起作用

java - Fabrica8、Vert.x、Karaf、Felix、Equinox、Spring DM 和 Fuse 以及 Docker 之间的区别

c++ - 将枚举类型转换为整数,反之亦然

java - 如果我在 GWT 中扩展 Widget,如何使用祖先的 EventBus?

java - Spring JMS 监听器容器并发属性不起作用

java - SSL套接字 : why do we need to do the handshake before accessing the server certificate?

java - 如何使用 addForcedEncode 写入 MSH 和 MSA 消息的所有字段(甚至为空)

java - 如何使用本地archetype-catalog.xml在intellij中创建maven项目

java - 如何从 Java 中的索引中获取枚举值?

c# - 自定义数据类型