Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8266631

StandardJavaFileManager: getJavaFileObjects() impl violates the spec

XMLWordPrintable

    • b28
    • Verified

        The following specification
        https://docs.oracle.com/en/java/javase/16/docs/api/java.compiler/javax/tools/StandardJavaFileManager.html#getJavaFileObjects(java.nio.file.Path...)
        asserts:

        =================================
        NullPointerException - if the given array contains null elements
        =================================

        However for OpenJDK implementation the following code produces no NPEs

        ========================
                var stJFM = new StandardJavaFileManager() {
                    @Override public int isSupportedOption(String option) { return 0; }
                    @Override public ClassLoader getClassLoader(Location location) { return null; }
                    @Override public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException { return null; }
                    @Override public String inferBinaryName(Location location, JavaFileObject file) { return null; }
                    @Override public boolean isSameFile(FileObject a, FileObject b) { return false; }
                    @Override public boolean handleOption(String current, Iterator<String> remaining) { return false; }
                    @Override public boolean hasLocation(Location location) { return false; }
                    @Override public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException { return null; }
                    @Override public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { return null; }
                    @Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { return null; }
                    @Override public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { return null; }
                    @Override public void flush() throws IOException { }
                    @Override public void close() throws IOException { }
                    @Override public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) { return null; }
                    @Override public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { return null; }
                    @Override public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { return null; }
                    @Override public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) { return null; }
                    @Override public void setLocation(Location location, Iterable<? extends File> files) throws IOException { }
                    @Override public Iterable<? extends File> getLocation(Location location) { return null; }
                };
                stJFM.getJavaFileObjects((Path)null);
                stJFM.getJavaFileObjects((Path)null, (Path)null);
                stJFM.getJavaFileObjects(Path.of("a"), (Path)null);
        ========================

        While the following call would generate an NPE:

                stJFM.getJavaFileObjects((Path[])null);

              jlahoda Jan Lahoda
              dbessono Dmitry Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: