Skip to content

Commit fa3849b

Browse files
jpgoughrfscholte
authored andcommitted
Fixes a bug where errors remain in the buffer without being captured
1 parent e67774c commit fa3849b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@ else if ( bufferAsString.startsWith("Error occurred during initialization of boo
690690
{
691691
errors.add( new CompilerMessage( bufferAsString, CompilerMessage.Kind.OTHER ) );
692692
}
693+
else if ( hasPointer )
694+
{
695+
//A compiler message remains in buffer at end of parse stream
696+
errors.add( parseModernError( exitCode, bufferAsString ) );
697+
}
693698
}
694699
return errors;
695700
}

plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/ErrorMessageParserTest.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,59 @@ public void testJvmError() throws Exception
906906
assertEquals( 1, compilerErrors.size() );
907907
}
908908

909+
public void testBadSourceFileError() throws Exception
910+
{
911+
String out = "/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java:12: error: cannot access Cls2\n" +
912+
" Cls2 tvar;\n" +
913+
" ^\n" +
914+
" bad source file: /MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls2.java\n" +
915+
" file does not contain class ch.pecunifex.x.Cls2\n" +
916+
" Please remove or make sure it appears in the correct subdirectory of the sourcepath.";
917+
918+
List<CompilerMessage> compilerErrors = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( out ) ));
919+
920+
assertNotNull( compilerErrors );
921+
922+
assertEquals( 1, compilerErrors.size() );
923+
924+
final CompilerMessage message = compilerErrors.get( 0 );
925+
validateBadSourceFile(message);
926+
}
927+
928+
public void testWarningFollowedByBadSourceFileError() throws Exception
929+
{
930+
String out = "/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java:3: warning: FontDesignMetrics is internal proprietary API and may be removed in a future release\n" +
931+
"import sun.font.FontDesignMetrics;\n" +
932+
" ^\n" +
933+
"/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java:12: error: cannot access Cls2\n" +
934+
" Cls2 tvar;\n" +
935+
" ^\n" +
936+
" bad source file: /MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls2.java\n" +
937+
" file does not contain class ch.pecunifex.x.Cls2\n" +
938+
" Please remove or make sure it appears in the correct subdirectory of the sourcepath.";
939+
940+
List<CompilerMessage> compilerErrors = JavacCompiler.parseModernStream( 1, new BufferedReader( new StringReader( out ) ));
941+
942+
assertNotNull( compilerErrors );
943+
944+
assertEquals( 2, compilerErrors.size() );
945+
946+
final CompilerMessage firstMessage = compilerErrors.get( 0 );
947+
assertEquals( "Is a Warning", CompilerMessage.Kind.WARNING, firstMessage.getKind() );
948+
assertEquals( "On Correct File","/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java", firstMessage.getFile() );
949+
assertEquals( "Internal API Warning", "FontDesignMetrics is internal proprietary API and may be removed in a future release", firstMessage.getMessage() );
950+
951+
final CompilerMessage secondMessage = compilerErrors.get( 1 );
952+
validateBadSourceFile(secondMessage);
953+
}
954+
955+
private void validateBadSourceFile(CompilerMessage message)
956+
{
957+
assertEquals( "Is an Error", CompilerMessage.Kind.ERROR, message.getKind() );
958+
assertEquals( "On Correct File","/MTOOLCHAINS-19/src/main/java/ch/pecunifex/x/Cls1.java", message.getFile() );
959+
assertTrue( "Message starts with access Error", message.getMessage().startsWith("error: cannot access Cls2") );
960+
}
961+
909962
private static void assertEquivalent(CompilerMessage expected, CompilerMessage actual){
910963
assertEquals("Message did not match", expected.getMessage(), actual.getMessage());
911964
assertEquals("Kind did not match", expected.getKind(), actual.getKind());

0 commit comments

Comments
 (0)