有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaXPKGINFO:always参数导致JavaC1.7.0_25崩溃

我的目标

我们需要将-Xpkginfo:always参数传递给javac编译器。我们正在使用javac 1.7.0_25-Xpkginfo可用于此版本,表示java doc

  1. 预期结果package-info.class应生成文件
  2. 实际结果javac编译器正在崩溃:

An exception has occurred in the compiler (1.7.0_25). 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.NullPointerException
        at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:291)
        at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:459)
        at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)
        at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)
        at com.sun.tools.javac.comp.Enter.complete(Enter.java:484)
        at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
        at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
        at com.sun.tools.javac.main.Main.compile(Main.java:439)
        at com.sun.tools.javac.main.Main.compile(Main.java:353)
        at com.sun.tools.javac.main.Main.compile(Main.java:342)
        at com.sun.tools.javac.main.Main.compile(Main.java:333)
        at com.sun.tools.javac.Main.compile(Main.java:76)
        at com.sun.tools.javac.Main.main(Main.java:61)

到目前为止我都试过了

它适用于Java1.8,但不幸的是,我们无法升级java编译器,因为我们仍然有旧的java代码

编辑

使用javac -X确保1.7.0_25-Xpkginfo参数可用。答案是肯定的:

PS C:\SVN\products\faa_mx\vs2017.install2> javac -X
  -Xlint                     Enable recommended warnings
  -Xlint:{all,cast,classfile,deprecation,dep-ann,divzero,empty,fallthrough,finally,options,overrides,path,processing,rawtypes,serial,static,try,unchecked,varargs,-cast,-classfile,-deprecation,-dep-ann,-divzero,-empty,-fallthrough,-finally,-options,-overrides,-path,-processing,-rawtypes,-serial,-static,-try,-unchecked,-varargs,none} Enable or disable specific warnings
  -Xbootclasspath/p:<path>   Prepend to the bootstrap class path
  -Xbootclasspath/a:<path>   Append to the bootstrap class path
  -Xbootclasspath:<path>     Override location of bootstrap class files
  -Djava.ext.dirs=<dirs>     Override location of installed extensions
  -Djava.endorsed.dirs=<dirs> Override location of endorsed standards path
  -Xmaxerrs <number>         Set the maximum number of errors to print
  -Xmaxwarns <number>        Set the maximum number of warnings to print
  -Xstdout <filename>        Redirect standard output
  -Xprint                    Print out a textual representation of specified types
  -XprintRounds              Print information about rounds of annotation processing
  -XprintProcessorInfo       Print information about which annotations a processor is asked to process
  -Xprefer:{source,newer}    Specify which file to read when both a source file and class file are found for an implicitly compiled class
  -Xpkginfo:{always,legacy,nonempty} Specify handling of package-info files

还尝试了1.7.0_80,同样的崩溃: An exception has occurred in the compiler (1.7.0_80).

java.lang.NullPointerException
        at com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:291)
        at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:459)
        at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:258)
        at com.sun.tools.javac.comp.Enter.classEnter(Enter.java:272)
        at com.sun.tools.javac.comp.Enter.complete(Enter.java:484)
        at com.sun.tools.javac.comp.Enter.main(Enter.java:469)
        at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:929)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
        at com.sun.tools.javac.main.Main.compile(Main.java:439)
        at com.sun.tools.javac.main.Main.compile(Main.java:353)
        at com.sun.tools.javac.main.Main.compile(Main.java:342)
        at com.sun.tools.javac.main.Main.compile(Main.java:333)
        at com.sun.tools.javac.Main.compile(Main.java:76)
        at com.sun.tools.javac.Main.main(Main.java:61)

替代解决方案

使用javac 1.8和使用命令行javac -source 1.7 -target 1.7 MyClass.java有意义吗


共 (1) 个答案

  1. # 1 楼答案

    在Java1.7中,如果将-Xpkginfo:always传递给javac,它似乎只接受package-info.java个空文件。如果你传递非空文件,我们就会崩溃

    使用1.8,javac能够在一个命令行中处理空文件和非空文件

    因此,1.7的解决方法是多次调用javac,一次调用所有空的package-info.java文件,另一次调用非空文件