Skip to content

Commit 4a5caa0

Browse files
cushonRealCLanger
authored andcommitted
8193277: SimpleFileObject inconsistency between getName and getShortName
Backport-of: 0720686
1 parent e7b89f7 commit 4a5caa0

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/file/PathFileObject.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public String getName() {
288288
return userPath.toString();
289289
}
290290

291+
@Override @DefinedBy(Api.COMPILER)
292+
public String getShortName() {
293+
return userPath.getFileName().toString();
294+
}
295+
291296
@Override
292297
public String inferBinaryName(Iterable<? extends Path> paths) {
293298
Path absPath = path.toAbsolutePath();
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2019, Google LLC. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8193277
27+
* @summary SimpleFileObject inconsistency between getName and getShortName
28+
* @library /tools/lib
29+
* @modules jdk.compiler/com.sun.tools.javac.api
30+
* jdk.compiler/com.sun.tools.javac.main
31+
* jdk.jdeps/com.sun.tools.classfile
32+
* @build toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox
33+
* @run main SymLinkShortNameTest
34+
*/
35+
36+
import java.nio.file.FileSystemException;
37+
import java.nio.file.Files;
38+
import java.nio.file.Path;
39+
import java.nio.file.Paths;
40+
import toolbox.JavacTask;
41+
import toolbox.Task.Expect;
42+
import toolbox.Task.OutputKind;
43+
import toolbox.Task.Result;
44+
import toolbox.TestRunner;
45+
import toolbox.TestRunner.Test;
46+
import toolbox.ToolBox;
47+
48+
public class SymLinkShortNameTest extends TestRunner {
49+
public static void main(String... args) throws Exception {
50+
new SymLinkShortNameTest().runTests(m -> new Object[] {Paths.get(m.getName())});
51+
}
52+
53+
private final ToolBox tb = new ToolBox();
54+
55+
public SymLinkShortNameTest() {
56+
super(System.err);
57+
}
58+
59+
@Test
60+
public void testJarSymlink(Path base) throws Exception {
61+
Files.createDirectories(base);
62+
Path b = base.resolve("B.java");
63+
tb.writeFile(b, "class B { int f() {} }");
64+
65+
Path a = base.resolve("A.java");
66+
try {
67+
Files.createSymbolicLink(a, b.getFileName());
68+
} catch (FileSystemException fse) {
69+
System.err.println("warning: test passes vacuously, sym-link could not be created");
70+
System.err.println(fse.getMessage());
71+
return;
72+
}
73+
74+
{
75+
Result result =
76+
new JavacTask(tb).options("-XDrawDiagnostics").files(a).run(Expect.FAIL);
77+
String output = result.getOutput(OutputKind.DIRECT);
78+
79+
String expected = "A.java:1:20: compiler.err.missing.ret.stmt";
80+
if (!output.contains(expected)) {
81+
throw new AssertionError(
82+
"expected output to contain: " + expected + "\nwas:\n" + output);
83+
}
84+
}
85+
{
86+
Result result = new JavacTask(tb).files(a).run(Expect.FAIL);
87+
String output = result.getOutput(OutputKind.DIRECT);
88+
89+
String expected = "A.java:1: error: missing return statement";
90+
if (!output.contains(expected)) {
91+
throw new AssertionError(
92+
"expected output to contain: " + expected + "\nwas:\n" + output);
93+
}
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)