6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file

Fri, 26 Feb 2010 15:26:58 -0800

author
jjg
date
Fri, 26 Feb 2010 15:26:58 -0800
changeset 510
72833a8a6086
parent 509
b030706da5b4
child 511
7b69c7083a97

6930076: "null" can incorrectly appear in error message compiler.err.error.reading.file
Reviewed-by: darcy

src/share/classes/com/sun/tools/javac/file/JavacFileManager.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/Paths.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/JavaCompiler.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Fri Feb 26 08:42:22 2010 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Fri Feb 26 15:26:58 2010 -0800
     1.3 @@ -260,7 +260,7 @@
     1.4                      archive = openArchive(directory);
     1.5                  } catch (IOException ex) {
     1.6                      log.error("error.reading.file",
     1.7 -                       directory, ex.getLocalizedMessage());
     1.8 +                       directory, getMessage(ex));
     1.9                      return;
    1.10                  }
    1.11              }
    1.12 @@ -489,7 +489,7 @@
    1.13                  archive = new MissingArchive(zipFileName);
    1.14              } catch (IOException ex) {
    1.15                  if (zipFileName.exists())
    1.16 -                    log.error("error.reading.file", zipFileName, ex.getLocalizedMessage());
    1.17 +                    log.error("error.reading.file", zipFileName, getMessage(ex));
    1.18                  archive = new MissingArchive(zipFileName);
    1.19              }
    1.20  
    1.21 @@ -838,4 +838,23 @@
    1.22          }
    1.23          throw new IllegalArgumentException("Invalid relative path: " + file);
    1.24      }
    1.25 +
    1.26 +    /**
    1.27 +     * Get a detail message from an IOException.
    1.28 +     * Most, but not all, instances of IOException provide a non-null result
    1.29 +     * for getLocalizedMessage().  But some instances return null: in these
    1.30 +     * cases, fallover to getMessage(), and if even that is null, return the
    1.31 +     * name of the exception itself.
    1.32 +     * @param e an IOException
    1.33 +     * @return a string to include in a compiler diagnostic
    1.34 +     */
    1.35 +    public static String getMessage(IOException e) {
    1.36 +        String s = e.getLocalizedMessage();
    1.37 +        if (s != null)
    1.38 +            return s;
    1.39 +        s = e.getMessage();
    1.40 +        if (s != null)
    1.41 +            return s;
    1.42 +        return e.toString();
    1.43 +    }
    1.44  }
     2.1 --- a/src/share/classes/com/sun/tools/javac/file/Paths.java	Fri Feb 26 08:42:22 2010 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/file/Paths.java	Fri Feb 26 15:26:58 2010 -0800
     2.3 @@ -320,7 +320,7 @@
     2.4                      addFile(f, warn);
     2.5                  }
     2.6              } catch (IOException e) {
     2.7 -                log.error("error.reading.file", jarFile, e.getLocalizedMessage());
     2.8 +                log.error("error.reading.file", jarFile, JavacFileManager.getMessage(e));
     2.9              }
    2.10          }
    2.11      }
     3.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Feb 26 08:42:22 2010 -0800
     3.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Fri Feb 26 15:26:58 2010 -0800
     3.3 @@ -558,7 +558,7 @@
     3.4              inputFiles.add(filename);
     3.5              return filename.getCharContent(false);
     3.6          } catch (IOException e) {
     3.7 -            log.error("error.reading.file", filename, e.getLocalizedMessage());
     3.8 +            log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
     3.9              return null;
    3.10          }
    3.11      }
    3.12 @@ -717,7 +717,7 @@
    3.13          try {
    3.14              tree = parse(filename, filename.getCharContent(false));
    3.15          } catch (IOException e) {
    3.16 -            log.error("error.reading.file", filename, e);
    3.17 +            log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
    3.18              tree = make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil());
    3.19          } finally {
    3.20              log.useSource(prev);

mercurial