-
Notifications
You must be signed in to change notification settings - Fork 61
add workaround to jdk bug https://bugs.openjdk.java.net/browse/JDK-8210649 found via https://issues.apache.org/jira/browse/MCOMPILER-346 add IT test from https://github.com/basil/MCOMPILER-346-mre #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1779407
7a39266
4e66eb4
a9ea63a
cc373ed
21fe710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,12 @@ | |
* under the License. | ||
*/ | ||
|
||
import org.codehaus.plexus.compiler.Compiler; | ||
import org.codehaus.plexus.compiler.CompilerConfiguration; | ||
import org.codehaus.plexus.compiler.CompilerMessage; | ||
import org.codehaus.plexus.compiler.CompilerException; | ||
import org.codehaus.plexus.compiler.CompilerResult; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
import org.codehaus.plexus.logging.AbstractLogEnabled; | ||
|
||
import javax.tools.Diagnostic; | ||
import javax.tools.DiagnosticCollector; | ||
|
@@ -36,15 +36,16 @@ | |
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
/** | ||
* @author Olivier Lamy | ||
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a> | ||
* @since 2.0 | ||
*/ | ||
@Component( role = Compiler.class ) | ||
public class JavaxToolsCompiler implements InProcessCompiler | ||
@Component( role = InProcessCompiler.class ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a change but fix a bug to be able to use dependency injection for this... |
||
public class JavaxToolsCompiler extends AbstractLogEnabled implements InProcessCompiler | ||
{ | ||
/** | ||
* is that thread safe ??? | ||
|
@@ -57,7 +58,7 @@ protected JavaCompiler newJavaCompiler() | |
return ToolProvider.getSystemJavaCompiler(); | ||
} | ||
|
||
private List<JavaCompiler> JAVA_COMPILERS = new CopyOnWriteArrayList<>(); | ||
private final List<JavaCompiler> JAVA_COMPILERS = new CopyOnWriteArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a class field used in a synchronized block, this is the place where |
||
|
||
private JavaCompiler getJavaCompiler( CompilerConfiguration compilerConfiguration ) | ||
{ | ||
|
@@ -111,14 +112,14 @@ public CompilerResult compileInProcess( String[] args, final CompilerConfigurati | |
CompilerMessage.Kind.ERROR ); | ||
return new CompilerResult( false, Collections.singletonList( message ) ); | ||
} | ||
final String sourceEncoding = config.getSourceEncoding(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup removing useless final |
||
final Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding ); | ||
final DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<>(); | ||
try ( final StandardJavaFileManager standardFileManager = | ||
String sourceEncoding = config.getSourceEncoding(); | ||
Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding ); | ||
DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<>(); | ||
try ( StandardJavaFileManager standardFileManager = | ||
compiler.getStandardFileManager( collector, null, sourceCharset ) ) | ||
{ | ||
|
||
final Iterable<? extends JavaFileObject> fileObjects = | ||
Iterable<? extends JavaFileObject> fileObjects = | ||
standardFileManager.getJavaFileObjectsFromStrings( Arrays.asList( sourceFiles ) ); | ||
|
||
/*(Writer out, | ||
|
@@ -130,14 +131,27 @@ public CompilerResult compileInProcess( String[] args, final CompilerConfigurati | |
|
||
List<String> arguments = Arrays.asList( args ); | ||
|
||
final JavaCompiler.CompilationTask task = | ||
JavaCompiler.CompilationTask task = | ||
compiler.getTask( null, standardFileManager, collector, arguments, null, fileObjects ); | ||
final Boolean result = task.call(); | ||
final ArrayList<CompilerMessage> compilerMsgs = new ArrayList<>(); | ||
Boolean result = task.call(); | ||
List<CompilerMessage> compilerMsgs = new ArrayList<>(); | ||
|
||
for ( Diagnostic<? extends JavaFileObject> diagnostic : collector.getDiagnostics() ) | ||
{ | ||
CompilerMessage.Kind kind = convertKind(diagnostic); | ||
String baseMessage = diagnostic.getMessage( null ); | ||
CompilerMessage.Kind kind = convertKind( diagnostic ); | ||
|
||
String baseMessage; | ||
try | ||
{ | ||
baseMessage = diagnostic.getMessage( Locale.getDefault() ); | ||
} | ||
catch ( AssertionError e ) | ||
{ | ||
// workaround for https://bugs.openjdk.java.net/browse/JDK-8210649 | ||
getLogger().debug( "Ignore Issue get JavaCompiler Diagnostic message (see https://bugs.openjdk.java.net/browse/JDK-8210649):" + e.getMessage(), e ); | ||
// in this case we try to replace the baseMessage with toString (hoping this does not throw a new exception.. | ||
baseMessage = diagnostic.toString(); | ||
} | ||
if ( baseMessage == null ) | ||
{ | ||
continue; | ||
|
@@ -185,7 +199,6 @@ public CompilerResult compileInProcess( String[] args, final CompilerConfigurati | |
finally | ||
{ | ||
releaseJavaCompiler( compiler, config ); | ||
|
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change that to be able to get logger.
The only usage of this in project is a manual construction of the only implementation available here and I bump version number.