8181897: JDK 9 change to symlink handling affects SourceFile attributes
authorjlahoda
Mon, 26 Jun 2017 17:00:45 +0200
changeset 47353 a6d4932d582e
parent 47352 33ac30e17843
child 47354 e8bda13da40b
8181897: JDK 9 change to symlink handling affects SourceFile attributes Summary: Using user provided path in toUri(). Reviewed-by: jjg
src/jdk.compiler/share/classes/com/sun/tools/javac/file/PathFileObject.java
test/langtools/tools/javac/file/SymLinkTest.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/PathFileObject.java	Mon Oct 16 11:20:59 2017 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/PathFileObject.java	Mon Jun 26 17:00:45 2017 +0200
@@ -316,6 +316,11 @@
             return isPathNameCompatible(userPath, simpleName, kind);
         }
 
+        @Override @DefinedBy(Api.COMPILER)
+        public URI toUri() {
+            return userPath.toUri().normalize();
+        }
+
         @Override
         PathFileObject getSibling(String baseName) {
             return new SimpleFileObject(fileManager,
--- a/test/langtools/tools/javac/file/SymLinkTest.java	Mon Oct 16 11:20:59 2017 -0700
+++ b/test/langtools/tools/javac/file/SymLinkTest.java	Mon Jun 26 17:00:45 2017 +0200
@@ -23,22 +23,26 @@
 
 /*
  * @test
- * @bug 8178017
+ * @bug 8178017 8181897
  * @summary JDK 9 change to symlink handling causes misleading
- *      class.public.should.be.in.file diagnostic
+ *      class.public.should.be.in.file diagnostic and SourceFile
+ *      attribute content
  * @library /tools/lib
  * @modules jdk.compiler/com.sun.tools.javac.api
  *          jdk.compiler/com.sun.tools.javac.main
+ *          jdk.jdeps/com.sun.tools.classfile
  * @build toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox
  * @run main SymLinkTest
  */
 
-import java.io.IOException;
 import java.nio.file.FileSystemException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
+import com.sun.tools.classfile.Attribute;
+import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.SourceFile_attribute;
 import toolbox.JavacTask;
 import toolbox.TestRunner;
 import toolbox.TestRunner.Test;
@@ -56,16 +60,16 @@
     }
 
     @Test
-    public void testgetKind(Path base) throws IOException {
+    public void testgetKind(Path base) throws Exception {
         test(base, "SOURCE");
     }
 
     @Test
-    public void testSymLink(Path base) throws IOException {
+    public void testSymLink(Path base) throws Exception {
         test(base, "SOURCE.java");
     }
 
-    void test(Path base, String name) throws IOException {
+    void test(Path base, String name) throws Exception{
         Path file = base.resolve(name);
         Path javaFile = base.resolve("HelloWorld.java");
         tb.writeFile(file,
@@ -89,6 +93,14 @@
             .files(javaFile)
             .run()
             .writeAll();
+
+        ClassFile cf = ClassFile.read(classes.resolve("HelloWorld.class"));
+        SourceFile_attribute sf = (SourceFile_attribute) cf.attributes.get(Attribute.SourceFile);
+        String sourceFile = sf.getSourceFile(cf.constant_pool);
+
+        if (!"HelloWorld.java".equals(sourceFile)) {
+            throw new AssertionError("Unexpected SourceFile attribute value: " + sourceFile);
+        }
     }
 }