Skip to content

Commit

Permalink
Ensure the product *.ini is loaded and saved using the native encoding
Browse files Browse the repository at this point in the history
The native launcher executable reads the product *.ini, e.g.,
eclipse.ini, using the native system encoding. Currently the *.ini is
loaded and saved in the launched Java application using the system
default encoding, but in Java 21 the default encoding is always UTF-8 so
we need to be more careful to always use the native encoding regardless
of the default encoding.
  • Loading branch information
merks committed Mar 15, 2024
1 parent 041c27e commit 9aad105
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.frameworkadmin.equinox;singleton:=true
Bundle-Version: 1.3.100.qualifier
Bundle-Version: 1.3.200.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Import-Package: org.eclipse.equinox.frameworkadmin;version="[2.0.0,3.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ void save(EquinoxLauncherData launcherData, boolean backup) throws IOException {

// only write the file if we actually have content
if (newlines.size() > 0) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(launcherConfigFile));) {
try (BufferedWriter bw = new BufferedWriter(
new FileWriter(launcherConfigFile, FileUtils.getNativeCharset()));) {
for (String arg : newlines) {
if (arg == null)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.*;
import java.net.*;
import java.nio.charset.Charset;
import java.util.*;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.URIUtil;
Expand Down Expand Up @@ -214,9 +215,12 @@ public static URI fromFileURL(String url) throws URISyntaxException {
* Loads an ini file, returning a list of all non-blank lines in the file. Like
* eclipseConfig.c/readConfigFile() comment lines ('#' its first character) are
* skipped too.
*
* This must load the content using the native system encoding because that's
* what the native launcher executable does.
*/
public static List<String> loadFile(File file) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(file));) {
try (BufferedReader br = new BufferedReader(new FileReader(file, getNativeCharset()));) {
String line;
List<String> list = new ArrayList<>();
while ((line = br.readLine()) != null) {
Expand All @@ -230,4 +234,13 @@ public static List<String> loadFile(File file) throws IOException {
}
}

/**
* The encoding used for reading and writing the ini file. This must be the
* native encoding; as of Java 21, the default encoding is UTF-8.
*/
public static Charset getNativeCharset() {
String encoding = System.getProperty("native.encoding"); //$NON-NLS-1$
return encoding != null ? Charset.forName(encoding) : Charset.defaultCharset();
}

}
2 changes: 1 addition & 1 deletion features/org.eclipse.equinox.p2.core.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.equinox.p2.core.feature"
label="%featureName"
version="1.7.100.qualifier"
version="1.7.200.qualifier"
provider-name="%providerName"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
2 changes: 1 addition & 1 deletion features/org.eclipse.equinox.p2.extras.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.equinox.p2.extras.feature"
label="%featureName"
version="1.4.2300.qualifier"
version="1.4.2400.qualifier"
provider-name="%providerName"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down

0 comments on commit 9aad105

Please sign in to comment.