JPlag
JPlag copied to clipboard
System Java Compiler behaves different depending on dependencies defined in maven
Just for documentation ..
Recently I've observed a (at least for me) strange behavior of the Java Compiler "ToolProvider.getSystemJavaCompiler()".
- If I try to compile a not-compilable java file in a "bare" maven project, I can obtain the errors as expected.
- If I add certain dependencies (I've first observed this when adding log4j), the compiler does not provide any information regarding compiler errors anymore.
To demonstrate this behavior, I've created an example repository for this: https://github.com/dfuchss/JavaCompilerIsStrange
In this repository I've added a simple main method that tries to parse the AST of an invalid Java File. The main method throws an exception if the diagnostics object contains no errors. This main method will be invoked by a single test. In my pom.xml I've created a profile "strange" that simply adds a dependency to the project (that is not used but obviously will be added to the classpath after activating the profile). For this example it's the "metainf-services" dependency. In the run.sh file, I simply execute mvn test twice. First without the profile activated and after that with the activated profile.
If you run the script you get a successful test (because the invalid syntax was detected) and an failed test (because the invalid syntax was not detected after adding the dependency)
See https://stackoverflow.com/questions/72737445/system-java-compiler-behaves-different-depending-on-dependencies-defined-in-mave#
Added as Bug to OpenJDK http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8289491
Bugfix is part of #463