Skip to content

Commit

Permalink
8265773: incorrect jdeps message "jdk8internals" to describe a remove…
Browse files Browse the repository at this point in the history
…d JDK internal API

Backport-of: b3b2bb2
  • Loading branch information
Alexander Scherbatiy committed Jun 24, 2021
1 parent ed48e5c commit dcd1044
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Analyzer.java
Expand Up @@ -405,6 +405,14 @@ private Jdk8Internals() {
}
}

/*
* Ignore the module name which should not be shown in the output
*/
@Override
public String name() {
return getName();
}

public boolean contains(Location location) {
String cn = location.getClassName();
int i = cn.lastIndexOf('.');
Expand Down
Expand Up @@ -312,7 +312,7 @@ public void printModuleDescriptor(Module module) {
* For non-JDK archives, this method returns the file name of the archive.
*/
String toTag(Archive source, String name, Archive target) {
if (source == target || !target.getModule().isNamed()) {
if (source == target || !target.getModule().isNamed() || Analyzer.notFound(target)) {
return target.getName();
}

Expand Down
66 changes: 66 additions & 0 deletions test/langtools/tools/jdeps/jdkinternals/RemovedJDKInternals.java
Expand Up @@ -31,9 +31,15 @@
* @run testng RemovedJDKInternals
*/

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.sun.tools.jdeps.DepsAnalyzer;
import com.sun.tools.jdeps.Graph;
Expand All @@ -42,6 +48,7 @@
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class RemovedJDKInternals {
Expand Down Expand Up @@ -115,6 +122,65 @@ public void runTest(String name, ModuleMetaData data) throws Exception {
}
}

private static final List<String> REMOVED_APIS = List.of(
"com.sun.image.codec.jpeg.JPEGCodec",
"sun.misc.Service",
"sun.misc.SoftCache",
"sun.reflect.Reflection"
);
private static final String REMOVED_INTERNAL_API = "JDK removed internal API";


@Test
public void removedInternalJDKs() throws IOException {
// verify the JDK removed internal API
JdepsRunner summary = JdepsRunner.run("-summary", CLASSES_DIR.toString());
Arrays.stream(summary.output()).map(l -> l.split(" -> "))
.map(a -> a[1]).filter(n -> n.equals(REMOVED_INTERNAL_API))
.findFirst().orElseThrow();

JdepsRunner jdeps = JdepsRunner.run("-verbose:class", CLASSES_DIR.toString());
String output = jdeps.stdout.toString();
Map<String, String> result = findDeps(output);
for (String cn : result.keySet()) {
String name = result.get(cn);
if (REMOVED_APIS.contains(cn)) {
assertEquals(name, REMOVED_INTERNAL_API);
} else if (cn.startsWith("sun.reflect")){
assertEquals(name, "JDK internal API (jdk.unsupported)");
} else {
assertEquals(name, "java.base");
}
}
REMOVED_APIS.stream().map(result::containsKey).allMatch(b -> b);
}

// Pattern used to parse lines
private static final Pattern linePattern = Pattern.compile(".*\r?\n");
private static final Pattern pattern = Pattern.compile("\\s+ -> (\\S+) +(.*)");

// Use the linePattern to break the given String into lines, applying
// the pattern to each line to see if we have a match
private static Map<String, String> findDeps(String out) {
Map<String, String> result = new LinkedHashMap<>();
Matcher lm = linePattern.matcher(out); // Line matcher
Matcher pm = null; // Pattern matcher
int lines = 0;
while (lm.find()) {
lines++;
CharSequence cs = lm.group(); // The current line
if (pm == null)
pm = pattern.matcher(cs);
else
pm.reset(cs);
if (pm.find())
result.put(pm.group(1), pm.group(2).trim());
if (lm.end() == out.length())
break;
}
return result;
}

private static final Map<String, String> REPLACEMENTS = Map.of(
"com.sun.image.codec.jpeg.JPEGCodec", "Use javax.imageio @since 1.4",
"sun.misc.Service", "Use java.util.ServiceLoader @since 1.6",
Expand Down

1 comment on commit dcd1044

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.