# HG changeset patch # User jjg # Date 1267226818 28800 # Node ID 72833a8a60863c5f4aa97109fc8c3019a69ea3da # Parent b030706da5b486b5eb0b41ac5d6f451efebf0a32 6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file Reviewed-by: darcy diff -r b030706da5b4 -r 72833a8a6086 src/share/classes/com/sun/tools/javac/file/JavacFileManager.java --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Fri Feb 26 08:42:22 2010 -0800 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Fri Feb 26 15:26:58 2010 -0800 @@ -260,7 +260,7 @@ archive = openArchive(directory); } catch (IOException ex) { log.error("error.reading.file", - directory, ex.getLocalizedMessage()); + directory, getMessage(ex)); return; } } @@ -489,7 +489,7 @@ archive = new MissingArchive(zipFileName); } catch (IOException ex) { if (zipFileName.exists()) - log.error("error.reading.file", zipFileName, ex.getLocalizedMessage()); + log.error("error.reading.file", zipFileName, getMessage(ex)); archive = new MissingArchive(zipFileName); } @@ -838,4 +838,23 @@ } throw new IllegalArgumentException("Invalid relative path: " + file); } + + /** + * Get a detail message from an IOException. + * Most, but not all, instances of IOException provide a non-null result + * for getLocalizedMessage(). But some instances return null: in these + * cases, fallover to getMessage(), and if even that is null, return the + * name of the exception itself. + * @param e an IOException + * @return a string to include in a compiler diagnostic + */ + public static String getMessage(IOException e) { + String s = e.getLocalizedMessage(); + if (s != null) + return s; + s = e.getMessage(); + if (s != null) + return s; + return e.toString(); + } } diff -r b030706da5b4 -r 72833a8a6086 src/share/classes/com/sun/tools/javac/file/Paths.java --- a/src/share/classes/com/sun/tools/javac/file/Paths.java Fri Feb 26 08:42:22 2010 -0800 +++ b/src/share/classes/com/sun/tools/javac/file/Paths.java Fri Feb 26 15:26:58 2010 -0800 @@ -320,7 +320,7 @@ addFile(f, warn); } } catch (IOException e) { - log.error("error.reading.file", jarFile, e.getLocalizedMessage()); + log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e)); } } } diff -r b030706da5b4 -r 72833a8a6086 src/share/classes/com/sun/tools/javac/main/JavaCompiler.java --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Feb 26 08:42:22 2010 -0800 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Fri Feb 26 15:26:58 2010 -0800 @@ -558,7 +558,7 @@ inputFiles.add(filename); return filename.getCharContent(false); } catch (IOException e) { - log.error("error.reading.file", filename, e.getLocalizedMessage()); + log.error("error.reading.file", filename, JavacFileManager.getMessage(e)); return null; } } @@ -717,7 +717,7 @@ try { tree = parse(filename, filename.getCharContent(false)); } catch (IOException e) { - log.error("error.reading.file", filename, e); + log.error("error.reading.file", filename, JavacFileManager.getMessage(e)); tree = make.TopLevel(List.nil(), null, List.nil()); } finally { log.useSource(prev);