10

我玩过 Java 8 ea b72,但出现编译器错误。有没有办法从 javac 获取更多信息,例如它当前正在处理的文件列表?如果我有一个大致的想法,我可能会找到解决方法,直到问题得到解决。

只是为了记录,这里是堆栈跟踪(如果在 IntelliJ IDEA 之外编译,它看起来很相似,顺便说一句):

An exception has occurred in the compiler (1.8.0-ea). 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.AssertionError: arraycode A
    at com.sun.tools.javac.jvm.Code.arraycode(Code.java:297)
    at com.sun.tools.javac.jvm.Gen.makeNewArray(Gen.java:1827)
    at com.sun.tools.javac.jvm.Gen.visitNewArray(Gen.java:1800)
    at com.sun.tools.javac.tree.JCTree$JCNewArray.accept(JCTree.java:1482)
    at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:893)
    at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:912)
    at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1746)
    at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1391)
    at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:893)
    at com.sun.tools.javac.jvm.Gen.visitReturn(Gen.java:1715)
    at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1310)
    at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:683)
    at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:718)
    at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:704)
    at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:755)
    at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1090)
    at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:835)
    at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:683)
    at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:718)
    at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:968)
    at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:941)
    at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:723)
    at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:683)
    at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2310)
    at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:751)
    at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1545)
    at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1509)
    at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:907)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:866)
    at com.sun.tools.javac.main.Main.compile(Main.java:506)
    at com.sun.tools.javac.main.Main.compile(Main.java:365)
    at com.sun.tools.javac.main.Main.compile(Main.java:354)
    at com.sun.tools.javac.main.Main.compile(Main.java:345)
    at com.sun.tools.javac.Main.compile(Main.java:94)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:477)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess0(JavacCompiler.java:551)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:526)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:167)
    at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:678)
    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:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:477)
    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)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:477)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    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:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:477)
    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)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:477)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
4

3 回答 3

3

这是最后的手段,但您可以尝试使用strace它来监视javac正在打开的文件。strace [your javac invocation] | grep '/directory/you/are/interested/in/可能会给你一些线索。

于 2013-01-23T19:29:09.763 回答
2

你试过javac的-verboseflag吗?如下所示的简单 ant 脚本可用于启用详细的编译器输出,

<project name="verbose_compile" default="compile" basedir=".">
  ...
  <target name="compile">
      <javac srcdir="${src.dir}" 
         destdir="${build.dir}"
         executable="${java8.home}/bin/javac" 
         classpath="..."
         fork="true" 
         verbose="true" />
  </target>
</project>

(看起来用户属性会在mavenmaven.compiler.verbose中完成同样的事情。)

我刚刚遇到了类似的情况。在 Windows 上,详细的输出向我显示了在错误之前正在编译的类。希望这将帮助您缩小问题的范围以找到解决方法。

于 2013-01-24T05:05:04.927 回答
0

这不是您的问题的解决方案。也许你可以弄清楚这可能出了什么问题。

下面是抛出“AssertionError”的方法。

/** Given a type, return its code for allocating arrays of that type.
*/
public static int arraycode(Type type)
{
    switch (type.tag)
    {
        case BYTE: return 8;
        case BOOLEAN: return 4;
        case SHORT: return 9;
        case CHAR: return 5;
        case INT: return 10;
        case LONG: return 11;
        case FLOAT: return 6;
        case DOUBLE: return 7;
        case CLASS: return 0;
        case ARRAY: return 1;
        default: throw new AssertionError("arraycode " + type);
    }
}

您可以在此处找到com.sun.tools.javac.jvm.Code类实现(尽管我找不到此类的正确版本,因为此类错误在第 298 行抛出,而在您的情况下为 297) . 它可能会有所帮助。

我找到了链接,Bug ID = 4901611,在以前的 Java 版本中显示了类似的错误。版本是 Java 1.5。在此链接中,您会发现当“带有 vararg 的通用方法”获得意外输入导致 AssertionError 时,会发生这种错误。没有给出解决方法,它已在下次更新中修复:(

于 2013-01-24T06:27:08.833 回答