8372155: ReleaseInfoPlugin doesn't handle input file as UTF-8 properly

Reviewed-by: alanb, jpai
This commit is contained in:
Severin Gehwolf 2025-11-24 22:14:24 +00:00
parent e00dec5808
commit 42b108b445
3 changed files with 92 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, 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
@ -25,11 +25,13 @@
package jdk.tools.jlink.internal.plugins;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.lang.module.ModuleDescriptor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
@ -107,8 +109,8 @@ public final class ReleaseInfoPlugin extends AbstractPlugin {
default: {
// --release-info <file>
Properties props = new Properties();
try (FileInputStream fis = new FileInputStream(operation)) {
props.load(fis);
try (Reader reader = Files.newBufferedReader(Path.of(operation))) {
props.load(reader); // Use reader API so as to read in as UTF-8
} catch (IOException exp) {
throw new UncheckedIOException(exp);
}

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015, 2025, 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
@ -39,6 +39,7 @@ release-info.argument=<file>|add:<key1>=<value1>:<key2>=<value2>:...|del:<key li
release-info.description=\
<file> option is to load release properties from the supplied file.\n\
\ The specified file is expected to be encoded in UTF-8.\n\
add: is to add properties to the 'release' file.\n\
Any number of <key>=<value> pairs can be passed.\n\
del: is to delete the list of keys in release file.
@ -46,7 +47,8 @@ del: is to delete the list of keys in release file.
release-info.usage=\
\ --release-info <file>|add:<key1>=<value1>:<key2>=<value2>:...|del:<key list>\n\
\ <file> option is to load release properties from\n\
\ the supplied file.\n\
\ the supplied file. The specified file is expected\n\
\ to be encoded in UTF-8.\n\
\ add: is to add properties to the 'release' file.\n\
\ Any number of <key>=<value> pairs can be passed.\n\
\ del: is to delete the list of keys in release file.

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 2025, IBM Corporation. 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.test.lib.process.*;
import jdk.test.lib.Asserts;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Files;
import java.util.Properties;
import jdk.tools.jlink.internal.LinkableRuntimeImage;
import tests.Helper;
/* @test
* @bug 8372155
* @summary Test the --release-info <file> plugin option
* @library ../../lib
* @library /test/lib
* @modules jdk.jlink/jdk.tools.jlink.internal
* jdk.jlink/jdk.tools.jimage
* java.base/jdk.internal.jimage
* @build tests.*
* @run main/othervm ReleaseInfoPluginTest
*/
public class ReleaseInfoPluginTest {
private static final String NON_ASCII = "ößäakl vendor oy";
private static final String IMPL = "IMPLEMENTOR";
private static final boolean LINKABLE_RUNTIME = LinkableRuntimeImage.isLinkableRuntime();
public static void main(String[] args) throws Throwable {
Helper helper = Helper.newHelper(LINKABLE_RUNTIME);
if (helper == null) {
System.err.println("Test not run");
return;
}
var utf8File = Path.of("release-info-utf-8.txt");
Files.writeString(utf8File, IMPL + "=\"" + NON_ASCII + "\"", StandardCharsets.UTF_8);
Path image = helper.generateDefaultImage(
new String[] {
"--release-info", utf8File.toString()
}, "java.base").assertSuccess();
// release file produced should have IMPLEMENTOR in
// UTF-8 encoding
Path release = image.resolve("release");
Properties props = new Properties();
try (Reader reader= Files.newBufferedReader(release)) {
props.load(reader); // Load as UTF-8
}
String noQuotesMods = ((String)props.get("MODULES")).replace("\"", "");
Asserts.assertEquals("java.base", noQuotesMods);
String noQuotesActual = ((String)props.get(IMPL)).replace("\"", "");
Asserts.assertEquals(NON_ASCII, noQuotesActual);
}
}