Skip to content

Commit

Permalink
8181897: JDK 9 change to symlink handling affects SourceFile attributes
Browse files Browse the repository at this point in the history
Summary: Using user provided path in toUri().
Reviewed-by: jjg
  • Loading branch information
jlahoda committed Jun 26, 2017
1 parent 0ce60f6 commit 69c5e44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ public boolean isNameCompatible(String simpleName, Kind kind) {
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,
Expand Down
24 changes: 18 additions & 6 deletions test/langtools/tools/javac/file/SymLinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,16 +60,16 @@ public SymLinkTest() {
}

@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,
Expand All @@ -89,6 +93,14 @@ void test(Path base, String name) throws IOException {
.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);
}
}
}

0 comments on commit 69c5e44

Please sign in to comment.