Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
8247407: tools/jlink/plugins/CompressorPluginTest.java test failing
Browse files Browse the repository at this point in the history
Reviewed-by: sundar, jlaskey
  • Loading branch information
jaikiran committed Jun 25, 2022
1 parent 7ac40f3 commit 9c92da5
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
Expand Up @@ -458,7 +458,11 @@ Node handleModulesSubTree(String name, ImageLocation loc) {
makeDirectories(path);
} else { // a resource
makeDirectories(childloc.buildName(true, true, false));
newResource(dir, childloc);
// if we have already created a resource for this name previously, then don't
// recreate it
if (!nodes.containsKey(childloc.getFullName(true))) {
newResource(dir, childloc);
}
}
});
dir.setCompleted(true);
Expand Down Expand Up @@ -753,6 +757,7 @@ public List<Node> getChildren() {
}

void addChild(Node node) {
assert !children.contains(node) : "Child " + node + " already added";
children.add(node);
}

Expand Down
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -695,7 +695,6 @@ javax/swing/JTable/8236907/LastVisibleRow.java 8284619 macosx-all

# core_tools

tools/jlink/plugins/CompressorPluginTest.java 8247407 generic-all

############################################################################

Expand Down
86 changes: 86 additions & 0 deletions test/jdk/tools/jimage/ImageReaderDuplicateChildNodesTest.java
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import jdk.internal.jimage.ImageReader;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @test
* @bug 8247407
* @summary Test that ImageReader doesn't create a Directory node with duplicate children
* @modules java.base/jdk.internal.jimage
* @run main ImageReaderDuplicateChildNodesTest
*/
public class ImageReaderDuplicateChildNodesTest {

/**
* Uses the ImageReader to open and read the JAVA_HOME/lib/modules image. Tests that the
* {@link ImageReader#findNode(String)} corresponding to a directory doesn't return a node
* with duplicate children in it.
*/
public static void main(final String[] args) throws Exception {
final Path imagePath = Paths.get(System.getProperty("java.home"), "lib", "modules");
if (!Files.exists(imagePath)) {
// skip the testing in the absence of the image file
System.err.println("Skipping test since " + imagePath + " is absent");
return;
}
System.out.println("Running test against image " + imagePath);
final String integersParentResource = "/modules/java.base/java/lang";
final String integerResource = integersParentResource + "/Integer.class";
try (final ImageReader reader = ImageReader.open(imagePath)) {
// find the child node/resource first
final ImageReader.Node integerNode = reader.findNode(integerResource);
if (integerNode == null) {
throw new RuntimeException("ImageReader could not locate " + integerResource
+ " in " + imagePath);
}
// now find the parent node (which will represent a directory)
final ImageReader.Node parent = reader.findNode(integersParentResource);
if (parent == null) {
throw new RuntimeException("ImageReader could not locate " + integersParentResource
+ " in " + imagePath);
}
// now verify that the parent node which is a directory, doesn't have duplicate children
final List<ImageReader.Node> children = parent.getChildren();
if (children == null || children.isEmpty()) {
throw new RuntimeException("ImageReader did not return any child resources under "
+ integersParentResource + " in " + imagePath);
}
final Set<ImageReader.Node> uniqueChildren = new HashSet<>();
for (final ImageReader.Node child : children) {
final boolean unique = uniqueChildren.add(child);
if (!unique) {
throw new RuntimeException("ImageReader returned duplicate child resource "
+ child + " under " + parent + " from image " + imagePath);
}
}
}
}
}

1 comment on commit 9c92da5

@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.