Skip to content

Commit b3b2bb2

Browse files
author
Mandy Chung
committed
8265773: incorrect jdeps message "jdk8internals" to describe a removed JDK internal API
Reviewed-by: alanb
1 parent 2780577 commit b3b2bb2

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ private Jdk8Internals() {
405405
}
406406
}
407407

408+
/*
409+
* Ignore the module name which should not be shown in the output
410+
*/
411+
@Override
412+
public String name() {
413+
return getName();
414+
}
415+
408416
public boolean contains(Location location) {
409417
String cn = location.getClassName();
410418
int i = cn.lastIndexOf('.');

src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public void printModuleDescriptor(Module module) {
312312
* For non-JDK archives, this method returns the file name of the archive.
313313
*/
314314
String toTag(Archive source, String name, Archive target) {
315-
if (source == target || !target.getModule().isNamed()) {
315+
if (source == target || !target.getModule().isNamed() || Analyzer.notFound(target)) {
316316
return target.getName();
317317
}
318318

test/langtools/tools/jdeps/jdkinternals/RemovedJDKInternals.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@
3131
* @run testng RemovedJDKInternals
3232
*/
3333

34+
import java.io.IOException;
3435
import java.nio.file.Path;
3536
import java.nio.file.Paths;
37+
import java.util.Arrays;
38+
import java.util.LinkedHashMap;
39+
import java.util.List;
3640
import java.util.Map;
41+
import java.util.regex.Matcher;
42+
import java.util.regex.Pattern;
3743

3844
import com.sun.tools.jdeps.DepsAnalyzer;
3945
import com.sun.tools.jdeps.Graph;
@@ -42,6 +48,7 @@
4248
import org.testng.annotations.Test;
4349

4450
import static org.testng.Assert.assertEquals;
51+
import static org.testng.Assert.assertFalse;
4552
import static org.testng.Assert.assertTrue;
4653

4754
public class RemovedJDKInternals {
@@ -115,6 +122,65 @@ public void runTest(String name, ModuleMetaData data) throws Exception {
115122
}
116123
}
117124

125+
private static final List<String> REMOVED_APIS = List.of(
126+
"com.sun.image.codec.jpeg.JPEGCodec",
127+
"sun.misc.Service",
128+
"sun.misc.SoftCache",
129+
"sun.reflect.Reflection"
130+
);
131+
private static final String REMOVED_INTERNAL_API = "JDK removed internal API";
132+
133+
134+
@Test
135+
public void removedInternalJDKs() throws IOException {
136+
// verify the JDK removed internal API
137+
JdepsRunner summary = JdepsRunner.run("-summary", CLASSES_DIR.toString());
138+
Arrays.stream(summary.output()).map(l -> l.split(" -> "))
139+
.map(a -> a[1]).filter(n -> n.equals(REMOVED_INTERNAL_API))
140+
.findFirst().orElseThrow();
141+
142+
JdepsRunner jdeps = JdepsRunner.run("-verbose:class", CLASSES_DIR.toString());
143+
String output = jdeps.stdout.toString();
144+
Map<String, String> result = findDeps(output);
145+
for (String cn : result.keySet()) {
146+
String name = result.get(cn);
147+
if (REMOVED_APIS.contains(cn)) {
148+
assertEquals(name, REMOVED_INTERNAL_API);
149+
} else if (cn.startsWith("sun.reflect")){
150+
assertEquals(name, "JDK internal API (jdk.unsupported)");
151+
} else {
152+
assertEquals(name, "java.base");
153+
}
154+
}
155+
REMOVED_APIS.stream().map(result::containsKey).allMatch(b -> b);
156+
}
157+
158+
// Pattern used to parse lines
159+
private static final Pattern linePattern = Pattern.compile(".*\r?\n");
160+
private static final Pattern pattern = Pattern.compile("\\s+ -> (\\S+) +(.*)");
161+
162+
// Use the linePattern to break the given String into lines, applying
163+
// the pattern to each line to see if we have a match
164+
private static Map<String, String> findDeps(String out) {
165+
Map<String, String> result = new LinkedHashMap<>();
166+
Matcher lm = linePattern.matcher(out); // Line matcher
167+
Matcher pm = null; // Pattern matcher
168+
int lines = 0;
169+
while (lm.find()) {
170+
lines++;
171+
CharSequence cs = lm.group(); // The current line
172+
if (pm == null)
173+
pm = pattern.matcher(cs);
174+
else
175+
pm.reset(cs);
176+
if (pm.find())
177+
result.put(pm.group(1), pm.group(2).trim());
178+
if (lm.end() == out.length())
179+
break;
180+
}
181+
return result;
182+
}
183+
118184
private static final Map<String, String> REPLACEMENTS = Map.of(
119185
"com.sun.image.codec.jpeg.JPEGCodec", "Use javax.imageio @since 1.4",
120186
"sun.misc.Service", "Use java.util.ServiceLoader @since 1.6",

0 commit comments

Comments
 (0)