-Xpkginfo:always参数导致javac 1.7.0_25崩溃 [英] -Xpkginfo:always arguments causes javac 1.7.0_25 to crashes
问题描述
我们需要将-Xpkginfo:always
参数传递给javac
编译器.我们正在使用javac 1.7.0_25
. -Xpkginfo
可用于该版本,说明 java doc .
We need to pass -Xpkginfo:always
arguments to javac
compiler. We are using javac 1.7.0_25
. -Xpkginfo
is available for this version says java doc.
- 预期结果:应生成
package-info.class
个文件 - 实际结果:
javac
编译器崩溃:
- Expected result:
package-info.class
files shall be generated - Actual result :
javac
compiler is crashing :
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)
到目前为止我已经尝试过的
它可以在Java 1.8上运行,但是很遗憾,由于我们仍然有旧的Java代码,因此无法升级Java编译器.
What I've tried so far
It works with java 1.8, but unfortunately, we can't upgrade our java compiler because we still have old java code.
使用javac -X
来确保1.7.0_25
具有-Xpkginfo
自变量.答案是肯定的:
Used javac -X
to make sure 1.7.0_25
has -Xpkginfo
argument available. Answer is yes :
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).
Also tried with 1.7.0_80, same crash :
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
是否有意义?
Alternative solution
Would that make sense to use javac 1.8
and use the command line javac -source 1.7 -target 1.7 MyClass.java
?
推荐答案
在Java 1.7中,如果将-Xpkginfo:always
传递给javac
,则它仅接受package-info.java
空文件.如果您传递非空文件,则会崩溃.
With java 1.7, it looks like that if you pass -Xpkginfo:always
to javac
, it only accepts package-info.java
empty files. If you pass non-empty files, we get the crash.
在1.8版本中,javac
能够在一个命令行中处理空文件和非空文件.
With 1.8, javac
is able to deal with empty and non empty files in one command line.
因此,1.7的解决方法是多次调用javac
,一次调用所有空的package-info.java
文件,另一次调用非空文件.
So, the workaround with 1.7 is to call javac
multiple time, once with all empty package-info.java
files, and another time with non-empty files.
这篇关于-Xpkginfo:always参数导致javac 1.7.0_25崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!