Skip to content
Permalink
Browse files
8278185: Custom JRE cannot find non-ASCII named module inside
Reviewed-by: naoto
  • Loading branch information
Toshio Nakamura authored and naotoj committed Dec 9, 2021
1 parent abebde7 commit fcd67a5242b7db06e4cb06b574972a463b209b2e
Showing 2 changed files with 99 additions and 1 deletion.
@@ -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) {
@@ -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 fcd67a5

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on fcd67a5 Dec 9, 2021

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.