Failure executing javac, but could not parse the error: How to find which source file caused error?

Failure executing javac, but could not parse the error: How to find which source file caused error?

我知道还有其他几个问题,有人遇到了问题,因为他们在编译时遇到了类似的错误,但这并不是完全相同的错误。在他们的例子中,问题似乎是 Maven 没有正确编译器的路径。在我的例子中,问题似乎是某处写错了 class/type。

编译结果:

COMPILATION ERROR : 
-------------------------------------------------------------
Failure executing javac, but could not parse the error:
An exception has occurred in the compiler (1.8.0_20). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.ClassCastException: com.sun.tools.javac.code.Type$ErrorType cannot be cast to com.sun.tools.javac.code.Type$ArrayType
    at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.validateAnnotatedType(Attr.java:4637)
    at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitMethodDef(Attr.java:4485)
    at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
    at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
    at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitClassDef(Attr.java:4552)
    at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
    at com.sun.tools.javac.comp.Attr.validateTypeAnnotations(Attr.java:4451)
    at com.sun.tools.javac.code.TypeAnnotations.run(TypeAnnotations.java:142)
    at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:155)
    at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:129)
    at com.sun.tools.javac.comp.Enter.complete(Enter.java:512)
    at com.sun.tools.javac.comp.Enter.main(Enter.java:471)
    at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
    at com.sun.tools.javac.main.Main.compile(Main.java:523)
    at com.sun.tools.javac.main.Main.compile(Main.java:381)
    at com.sun.tools.javac.main.Main.compile(Main.java:370)
    at com.sun.tools.javac.main.Main.compile(Main.java:361)
    at com.sun.tools.javac.Main.compile(Main.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:554)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:161)
    at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:605)
    at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    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.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

ErrorType (https://docs.oracle.com/javase/7/docs/api/javax/lang/model/type/ErrorType.html) 表示某种 class 或接口等未正确编写且无法建模。

ArrayType 只是表示它是一个数组。所以很可能这意味着我在某个地方使用 incomplete/missing class 作为数组。

这也是在 visitMethodDef() -> validateAnnotatedType() 中,这意味着这可能是方法的 return type/parameter?

这可能是什么原因造成的?为什么编译器不说明这发生在源代码中的什么位置?

我正在使用 Maven 2.4 和 JDK 1.8。我编译一般没有问题。

这是我的 Maven pom.xml 文件的片段:

 <build>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
              <downloadSources>true</downloadSources>
              <downloadJavadocs>true</downloadJavadocs>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>PATH.TO.MAIN.CLASS</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>  
    </plugins>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.fxml</include>
                <include>**/*.css</include>
                <include>**/*.properties</include>
                <include>**/*.png</include>
                <include>**/*.gif</include>
                <include>**/*.xml</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
</build>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

我也尝试使用 Maven 的更多输出进行编译,但我没有看到任何对检测错误有用的信息。

为什么编译器不显示不完整类型在哪个文件中?我怎样才能以显示哪个文件有错误的方式进行编译?是否可以验证单个文件以发现此类错误?

一个 simillair 错误在这里有一个错误报告(https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=2ahUKEwix2evZmt3cAhXoNJoKHWQ7BXAQFjABegQICRAB&url=https%3A%2F%2Fnetbeans.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D247421&usg=AOvVaw3ulnafW3ET1VWqw43wAEC0)有人试图合并 Lists/arrays 但语法不正确。但是有没有办法找出哪个文件包含错误?

我找到问题所在了。

我有一个方法声明:

public synchronized static T[] <T> foo(...)

而不是

public synchronized static <T> T[] foo(...)

令人难以置信的是,编译器甚至没有说明它是哪个源文件。