0

My goal

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.

  1. Expected result: package-info.class files shall be generated
  2. 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)

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.

EDIT

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

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)

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?

Community
  • 1
  • 1
peterphonic
  • 951
  • 1
  • 19
  • 38
  • Run the command `javac -X` and see if `-Xpkginfo` appears in the output. If it doesn't then it is not supported. If you can't upgrade to JDK 1.8, maybe try a later version of JDK 1.7 where the bug may have been fixed. Maybe try [7u80](https://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html). – Abra Dec 01 '19 at 14:53
  • @ArvindKumarAvinash Reading this :https://stackoverflow.com/questions/22610400/can-program-developed-with-java-8-be-run-on-java-7. Could I do something like this `javac -source 1.7 -target 1.7 MyClass.java` ?. The poster says it is not recommended. We have drools 5.6 in our project. It is quite old – peterphonic Dec 01 '19 at 14:55
  • @Abra Post updated. `-Xpkginfo` appears in the output for 7u25. Also tried 7u80, I have same crash. Would it be possible to use `javac` 1.8 with `-source 1.7` and `-target 1.7`? Would that make sense at all? – peterphonic Dec 01 '19 at 16:36

1 Answers1

0

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.

With 1.8, javac is able to deal with empty and non empty files in one command line.

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.

peterphonic
  • 951
  • 1
  • 19
  • 38