Skip to content

Commit

Permalink
8278185: Custom JRE cannot find non-ASCII named module inside
Browse files Browse the repository at this point in the history
Backport-of: fcd67a5242b7db06e4cb06b574972a463b209b2e
  • Loading branch information
Toshio Nakamura authored and Paul Hohensee committed Feb 25, 2022
1 parent 6650652 commit df5a29c
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static int stringFromByteBufferMatches(ByteBuffer buffer, int offset, String str
return -1;
}
}
return length;
return current - offset + length;
}

static int mutf8FromStringLength(String s) {
Expand Down
98 changes: 98 additions & 0 deletions test/jdk/tools/jimage/JImageNonAsciiNameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2021, 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 java.nio.file.Path;
import jdk.internal.jimage.BasicImageReader;
import jdk.internal.jimage.ImageLocation;
import jdk.test.lib.compiler.InMemoryJavaCompiler;
import jdk.test.lib.util.JarBuilder;

import tests.Helper;
import tests.JImageGenerator;
import tests.Result;

/*
* @test
* @bug 8278185
* @summary Test non-ASCII path in custom JRE
* @library ../lib
* /test/lib
* @modules java.base/jdk.internal.jimage
* jdk.jdeps/com.sun.tools.classfile
* jdk.jlink/jdk.tools.jimage
* @build tests.*
* @run main/othervm JImageNonAsciiNameTest
*/

public class JImageNonAsciiNameTest {
private final static String moduleName = "A_module";
private final static String packageName = "test.\u3042"; //non-ASCII
private final static String className = "A";
private final static String fullName = packageName + "." + className;
private static Helper helper;

public static void main(String[] args) throws Exception {
helper = Helper.newHelper();
if (helper == null) {
System.err.println("Test not run");
return;
}

String source =
"package "+packageName+";" +
"public class "+className+" {" +
" public static void main(String[] args) {}" +
"}";
String moduleInfo = "module " + moduleName + " {}";

// Using InMemory features to avoid generating non-ASCII name file
byte[] byteA = InMemoryJavaCompiler.compile(fullName, source);
byte[] byteModule = InMemoryJavaCompiler.compile(
"module-info", moduleInfo);

Path jarDir = helper.getJarDir();
JarBuilder jb = new JarBuilder(
jarDir.resolve(moduleName + ".jar").toString());
jb.addEntry(fullName.replace(".","/") + ".class", byteA);
jb.addEntry("module-info.class", byteModule);
jb.build();

Path outDir = helper.createNewImageDir(moduleName);

Result result = JImageGenerator.getJLinkTask()
.modulePath(helper.defaultModulePath())
.output(outDir)
.addMods(moduleName)
.call();
Path testImage = result.assertSuccess();

BasicImageReader bir = BasicImageReader.open(
testImage.resolve("lib").resolve("modules"));
ImageLocation loc = bir.findLocation(moduleName,
fullName.replace(".","/") + ".class");
if (loc == null) {
throw new RuntimeException("Failed to find " +
fullName + " in module " +moduleName);
}
}
}

1 comment on commit df5a29c

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