6625520: javac handles missing entries on classpath badly

Tue, 17 Jun 2008 10:44:32 -0700

author
jjg
date
Tue, 17 Jun 2008 10:44:32 -0700
changeset 56
f9a4b9e1a521
parent 50
b9bcea8bbe24
child 57
aa67a5da66e3

6625520: javac handles missing entries on classpath badly
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/file/JavacFileManager.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/JavapFileManager.java file | annotate | diff | comparison | revisions
test/tools/javac/T6625520.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Mon Jun 16 13:28:00 2008 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Tue Jun 17 10:44:32 2008 -0700
     1.3 @@ -665,7 +665,8 @@
     1.4              } catch (FileNotFoundException ex) {
     1.5                  archive = new MissingArchive(zipFileName);
     1.6              } catch (IOException ex) {
     1.7 -                log.error("error.reading.file", zipFileName, ex.getLocalizedMessage());
     1.8 +                if (zipFileName.exists())
     1.9 +                    log.error("error.reading.file", zipFileName, ex.getLocalizedMessage());
    1.10                  archive = new MissingArchive(zipFileName);
    1.11              }
    1.12  
     2.1 --- a/src/share/classes/com/sun/tools/javap/JavapFileManager.java	Mon Jun 16 13:28:00 2008 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javap/JavapFileManager.java	Tue Jun 17 10:44:32 2008 -0700
     2.3 @@ -25,16 +25,13 @@
     2.4  
     2.5  package com.sun.tools.javap;
     2.6  
     2.7 -import java.io.File;
     2.8  import java.io.PrintWriter;
     2.9  import java.nio.charset.Charset;
    2.10 -import javax.tools.Diagnostic;
    2.11  import javax.tools.DiagnosticListener;
    2.12  import javax.tools.JavaFileObject;
    2.13  
    2.14  import com.sun.tools.javac.file.JavacFileManager;
    2.15  import com.sun.tools.javac.util.Context;
    2.16 -import com.sun.tools.javac.util.JCDiagnostic;
    2.17  
    2.18  /**
    2.19   *  javap's implementation of JavaFileManager.
    2.20 @@ -52,29 +49,8 @@
    2.21      static JavapFileManager create(final DiagnosticListener<? super JavaFileObject> dl, PrintWriter log, Options options) {
    2.22          Context javac_context = new Context();
    2.23  
    2.24 -        if (dl != null) {
    2.25 -            // Workaround bug 6625520: javac handles missing entries on classpath badly
    2.26 -            // Ignore spurious errors for missing files
    2.27 -            DiagnosticListener<JavaFileObject> wrapper = new DiagnosticListener<JavaFileObject>() {
    2.28 -                public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
    2.29 -                    if (diagnostic instanceof JCDiagnostic) {
    2.30 -                        JCDiagnostic jcd = (JCDiagnostic) diagnostic;
    2.31 -                        if (jcd.getCode().equals("compiler.err.error.reading.file")) {
    2.32 -                            Object[] args = jcd.getArgs();
    2.33 -                            if (args.length > 0 && args[0] != null && args[0].toString().length() > 0) {
    2.34 -                                File f = new File(args[0].toString());
    2.35 -                                if (!f.exists())
    2.36 -                                    return;
    2.37 -                            }
    2.38 -                        }
    2.39 -
    2.40 -                    }
    2.41 -                    dl.report(diagnostic);
    2.42 -                }
    2.43 -            };
    2.44 -            javac_context.put(DiagnosticListener.class, wrapper);
    2.45 -        }
    2.46 -
    2.47 +        if (dl != null)
    2.48 +            javac_context.put(DiagnosticListener.class, dl);
    2.49          javac_context.put(com.sun.tools.javac.util.Log.outKey, log);
    2.50  
    2.51          return new JavapFileManager(javac_context, null);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/T6625520.java	Tue Jun 17 10:44:32 2008 -0700
     3.3 @@ -0,0 +1,54 @@
     3.4 +/*
     3.5 + * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.24 + * have any questions.
    3.25 + */
    3.26 +
    3.27 +import java.io.*;
    3.28 +import java.util.*;
    3.29 +import javax.tools.*;
    3.30 +import com.sun.tools.javac.file.*;
    3.31 +import com.sun.tools.javac.util.*;
    3.32 +
    3.33 +/*
    3.34 + * @test
    3.35 + * @bug 6625520
    3.36 + * @summary javac handles missing entries on classpath badly
    3.37 + */
    3.38 +public class T6625520 {
    3.39 +    public static void main(String[] args) throws Exception {
    3.40 +        new T6625520().run();
    3.41 +    }
    3.42 +
    3.43 +    void run() throws Exception {
    3.44 +        Context c = new Context();
    3.45 +        DiagnosticCollector<JavaFileObject> dc =
    3.46 +            new DiagnosticCollector<JavaFileObject>();
    3.47 +        c.put(DiagnosticListener.class, dc);
    3.48 +        StandardJavaFileManager fm = new JavacFileManager(c, false, null);
    3.49 +        fm.setLocation(StandardLocation.CLASS_PATH,
    3.50 +                       Arrays.asList(new File("DOES_NOT_EXIST.jar")));
    3.51 +        FileObject fo = fm.getFileForInput(StandardLocation.CLASS_PATH,
    3.52 +                                           "p", "C.java");
    3.53 +        System.err.println(fo + "\n" + dc.getDiagnostics());
    3.54 +        if (dc.getDiagnostics().size() > 0)
    3.55 +            throw new Exception("unexpected diagnostics found");
    3.56 +    }
    3.57 +}
    3.58 \ No newline at end of file

mercurial