@@ -258,18 +258,22 @@ private String getOutOfProcessJavacVersion(String executable) throws CompilerExc
258258 * up to 21 (https://docs.oracle.com/en/java/javase/21/docs/specs/man/javac.html#standard-options)
259259 */
260260 cli .addArguments (new String [] {"-version" }); //
261- CommandLineUtils . StringStreamConsumer out = new CommandLineUtils . StringStreamConsumer ();
262- CommandLineUtils . StringStreamConsumer err = new CommandLineUtils . StringStreamConsumer ();
261+ List < String > out = new ArrayList <> ();
262+ List < String > err = new ArrayList <> ();
263263 try {
264- int exitCode = CommandLineUtils .executeCommandLine (cli , out , err );
264+ int exitCode = CommandLineUtils .executeCommandLine (cli , out :: add , err :: add );
265265 if (exitCode != 0 ) {
266266 throw new CompilerException ("Could not retrieve version from " + executable + ". Exit code "
267- + exitCode + ", Output: " + out .getOutput () + ", Error: " + err .getOutput ());
267+ + exitCode + ", Output: " + String .join (System .lineSeparator (), out ) + ", Error: "
268+ + String .join (System .lineSeparator (), err ));
268269 }
269270 } catch (CommandLineException e ) {
270271 throw new CompilerException ("Error while executing the external compiler " + executable , e );
271272 }
272- version = tryParseVersion (out .getOutput ().trim ());
273+ version = tryParseVersion (out );
274+ if (version == null ) {
275+ version = tryParseVersion (err );
276+ }
273277 VERSION_PER_EXECUTABLE .put (executable , version );
274278 }
275279 return version ;
@@ -283,15 +287,17 @@ static String extractMajorAndMinorVersion(String text) {
283287 return matcher .group ();
284288 }
285289
286- private String tryParseVersion (String version ) {
287- if (version .startsWith ("javac " )) {
288- version = version .substring (6 );
289- if (version .startsWith ("1." )) {
290- version = version .substring (0 , 3 );
291- } else {
292- version = version .substring (0 , 2 );
290+ private String tryParseVersion (List <String > versions ) {
291+ for (String version : versions ) {
292+ if (version .startsWith ("javac " )) {
293+ version = version .substring (6 );
294+ if (version .startsWith ("1." )) {
295+ version = version .substring (0 , 3 );
296+ } else {
297+ version = version .substring (0 , 2 );
298+ }
299+ return version ;
293300 }
294- return version ;
295301 }
296302 return null ;
297303 }
0 commit comments