From 679a8870ed8be939d91467d5cc360823819ca0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Tue, 2 Jul 2024 11:12:10 +0200 Subject: [PATCH] Replace "UTF8" with StandardCharsets.UTF_8 Avoids NON-NLS and possible UnsupportedEncodingException --- .../jdt/bcoview/compare/TypedElement.java | 4 +-- .../eclipse/jdt/bcoview/views/HelpUtils.java | 3 +- .../junit/runner/RemoteTestRunner.java | 11 +++--- .../jdt/ui/tests/chkpii/HTMLTidyTest.java | 3 +- .../BuildpathProblemQuickFixTest.java | 3 +- .../tests/quickfix/AnnotateAssistTest1d5.java | 9 ++--- .../tests/quickfix/AnnotateAssistTest1d8.java | 35 +++++++++++++------ .../jdt/internal/corext/util/History.java | 3 +- .../ui/jarpackager/JarPackageReader.java | 3 +- .../ui/jarpackager/JarPackageWriter.java | 6 ++-- .../preferences/formatter/ModifyDialog.java | 7 ++-- 11 files changed, 53 insertions(+), 34 deletions(-) diff --git a/org.eclipse.jdt.bcoview/src/org/eclipse/jdt/bcoview/compare/TypedElement.java b/org.eclipse.jdt.bcoview/src/org/eclipse/jdt/bcoview/compare/TypedElement.java index 40d0777063c..18f4d6a2db5 100644 --- a/org.eclipse.jdt.bcoview/src/org/eclipse/jdt/bcoview/compare/TypedElement.java +++ b/org.eclipse.jdt.bcoview/src/org/eclipse/jdt/bcoview/compare/TypedElement.java @@ -15,7 +15,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.BitSet; import org.eclipse.jdt.bcoview.asm.DecompiledClass; @@ -111,7 +111,7 @@ protected InputStream createStream() throws CoreException { + " is not supported by current JVM", //$NON-NLS-1$ e)); } - final byte[] bytes = decompiledClass.getText().getBytes(Charset.forName("UTF-8")); //$NON-NLS-1$ + final byte[] bytes = decompiledClass.getText().getBytes(StandardCharsets.UTF_8); // use internal buffering to prevent multiple calls to this method Display.getDefault().syncExec(() -> setContent(bytes)); diff --git a/org.eclipse.jdt.bcoview/src/org/eclipse/jdt/bcoview/views/HelpUtils.java b/org.eclipse.jdt.bcoview/src/org/eclipse/jdt/bcoview/views/HelpUtils.java index bde63d85192..b31c634e8e6 100644 --- a/org.eclipse.jdt.bcoview/src/org/eclipse/jdt/bcoview/views/HelpUtils.java +++ b/org.eclipse.jdt.bcoview/src/org/eclipse/jdt/bcoview/views/HelpUtils.java @@ -18,6 +18,7 @@ import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Scanner; import org.objectweb.asm.util.Printer; @@ -108,7 +109,7 @@ private static String readFullSpec() { URL helpResource = toUrl(SPECS_HTML); StringBuilder sb = new StringBuilder(); boolean foundContentStart = false; - try (BufferedReader in = new BufferedReader(new InputStreamReader(helpResource.openStream(), "UTF-8"))) { //$NON-NLS-1$ + try (BufferedReader in = new BufferedReader(new InputStreamReader(helpResource.openStream(), StandardCharsets.UTF_8))) { String line; while ((line = in.readLine()) != null) { if (!foundContentStart) { diff --git a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java index e3187d4df80..8e9b6390cd7 100644 --- a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java +++ b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java @@ -25,6 +25,7 @@ import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.net.Socket; +import java.nio.charset.StandardCharsets; import java.util.Vector; import org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader; @@ -386,7 +387,7 @@ public void setLoader(ITestLoader newInstance) { } private void readPackageNames(String pkgNameFile) throws IOException { - try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(pkgNameFile)), "UTF-8"))) { //$NON-NLS-1$ + try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(pkgNameFile)), StandardCharsets.UTF_8))) { String line; Vector list= new Vector<>(); while ((line= br.readLine()) != null) { @@ -403,7 +404,7 @@ private void readPackageNames(String pkgNameFile) throws IOException { } private void readTestNames(String testNameFile) throws IOException { - try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testNameFile)), "UTF-8"))) { //$NON-NLS-1$ + try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testNameFile)), StandardCharsets.UTF_8))) { String line; Vector list= new Vector<>(); while ((line= br.readLine()) != null) { @@ -420,7 +421,7 @@ private void readTestNames(String testNameFile) throws IOException { } private void readFailureNames(String testFailureFile) throws IOException { - try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testFailureFile)), "UTF-8"))) { //$NON-NLS-1$ + try(BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testFailureFile)), StandardCharsets.UTF_8))) { String line; Vector list= new Vector<>(); while ((line= br.readLine()) != null) { @@ -649,12 +650,12 @@ protected boolean connect() { try{ fClientSocket= new Socket(fHost, fPort); try { - fWriter= new PrintWriter(new BufferedWriter(new OutputStreamWriter(fClientSocket.getOutputStream(), "UTF-8")), false/*true*/); //$NON-NLS-1$ + fWriter= new PrintWriter(new BufferedWriter(new OutputStreamWriter(fClientSocket.getOutputStream(), StandardCharsets.UTF_8)), false/*true*/); } catch (UnsupportedEncodingException e1) { fWriter= new PrintWriter(new BufferedWriter(new OutputStreamWriter(fClientSocket.getOutputStream())), false/*true*/); } try { - fReader= new BufferedReader(new InputStreamReader(fClientSocket.getInputStream(), "UTF-8")); //$NON-NLS-1$ + fReader= new BufferedReader(new InputStreamReader(fClientSocket.getInputStream(), StandardCharsets.UTF_8)); } catch (UnsupportedEncodingException e1) { fReader= new BufferedReader(new InputStreamReader(fClientSocket.getInputStream())); } diff --git a/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/HTMLTidyTest.java b/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/HTMLTidyTest.java index 691feb6e9d5..37ca286fd65 100644 --- a/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/HTMLTidyTest.java +++ b/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/HTMLTidyTest.java @@ -24,6 +24,7 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -87,7 +88,7 @@ public void testHTML() throws Exception { fworkspacePathLength= workspacePath.length(); File chkpiiResults= new File(hostWorkspace, "chkpiiResults"); File tidy= new File(chkpiiResults, "tidy.txt"); - fTidyResults= new OutputStreamWriter(new FileOutputStream(tidy), "UTF-8"); + fTidyResults= new OutputStreamWriter(new FileOutputStream(tidy), StandardCharsets.UTF_8); String startTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); fTidyResults.write(getClass().getName() + " started at " + startTime + "\n"); fIgnores= getIgnores(); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/BuildpathProblemQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/BuildpathProblemQuickFixTest.java index 6365ad87f31..a06af9dd560 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/BuildpathProblemQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/BuildpathProblemQuickFixTest.java @@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.junit.After; @@ -65,7 +66,7 @@ public void tearDown() throws Exception { public IPath addFile(IPath root, String fileName, String contents) throws CoreException, IOException { IPath filePath= root.append(fileName); - createFile(filePath, contents.getBytes("UTF8")); //$NON-NLS-1$ + createFile(filePath, contents.getBytes(StandardCharsets.UTF_8)); return filePath; } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java index ce223867ad8..c2835c2e7e1 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; import java.util.List; import org.junit.After; @@ -249,7 +250,7 @@ class pack/age/MyMap (TK;)T0V; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -325,7 +326,7 @@ class pack/age/X ([[ILjava/util/List;)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -404,7 +405,7 @@ class pack/age/X (Ljava/util/List;[I)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -481,7 +482,7 @@ class pack/age/X (Ljava/lang/String;)V """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java index c97b561e697..748f40487bc 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java @@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -49,6 +50,7 @@ import org.eclipse.jdt.internal.core.ClasspathAttribute; import org.eclipse.jdt.internal.core.ClasspathEntry; +import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.examples.MyClasspathContainerInitializer; @@ -193,7 +195,7 @@ class pack/age/X ([IL1java/util/List;)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -260,7 +262,18 @@ public interface X { """ }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); + + IResource resource = fJProject1.getProject().getFile("lib.jar"); + assertTrue(resource.exists()); IType type= fJProject1.findType(X_PATH.replace('/', '.')); + JavaCore.runReadOnly(()->{ + +// JavaCore.getClasspathContainer(resource.getFullPath(), fJProject1); + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + JavaCore.getClasspathContainer(resource.getFullPath(), fJProject1); + manager.containers = new HashMap(5); + JavaCore.getClasspathContainer(resource.getFullPath(), fJProject1); + }); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); try { @@ -306,7 +319,7 @@ class pack/age/X ([Ljava/lang/Object;L1java/util/List<+1Ljava/lang/Number;>;)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -383,7 +396,7 @@ public interface X { "class pack/age/X\n" + "test\n"; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -464,7 +477,7 @@ class pack/age/X ([1[ILjava/util/List;)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -545,7 +558,7 @@ class pack/age/X ([1[ILjava/util/List;)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -626,7 +639,7 @@ class pack/age/X ([[1[ILjava/util/List;)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -705,7 +718,7 @@ class pack/age/X ()[Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -784,7 +797,7 @@ class pack/age/X ()[Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -863,7 +876,7 @@ class pack/age/X (Ljava/util/List;[I)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -944,7 +957,7 @@ class pack/age/X (Ljava/util/List;[[1I)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -1023,7 +1036,7 @@ class pack/age/X (Ljava/util/List;[Ljava/lang/String;)Ljava/lang/String; """; ensureExists(annotationFile.getParent()); - annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); + annotationFile.create(new ByteArrayInputStream(initialContent.getBytes(StandardCharsets.UTF_8)), 0, null); IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/History.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/History.java index 39006f1bb20..d9a046c579c 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/History.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/util/History.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Hashtable; import java.util.Iterator; @@ -168,7 +169,7 @@ public synchronized void load() { IPath stateLocation= JavaPlugin.getDefault().getStateLocation().append(fFileName); File file= stateLocation.toFile(); if (file.exists()) { - try (InputStreamReader reader= new InputStreamReader(new FileInputStream(file), "utf-8")) {//$NON-NLS-1$ + try (InputStreamReader reader= new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) { load(new InputSource(reader)); } catch (IOException | CoreException e) { JavaPlugin.log(e); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java index 73ed3113edf..37d077415eb 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageReader.java @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -196,7 +197,7 @@ private void xmlReadRefactoring(JarPackageData jarPackage, Element element) thro service.connect(); value= element.getAttribute("refactoring" + count); //$NON-NLS-1$ while (value != null && !"".equals(value)) { //$NON-NLS-1$ - final ByteArrayInputStream stream= new ByteArrayInputStream(value.getBytes("UTF-8")); //$NON-NLS-1$ + final ByteArrayInputStream stream= new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8)); try { final RefactoringHistory history= service.readRefactoringHistory(stream, RefactoringDescriptor.NONE); if (history != null) { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java index c5933bb78b0..c5b1601094e 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarPackageWriter.java @@ -19,7 +19,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -173,11 +173,9 @@ private void xmlWriteRefactoring(JarPackageData jarPackage, Document document, E try { final ByteArrayOutputStream stream= new ByteArrayOutputStream(); service.writeRefactoringDescriptors(new RefactoringDescriptorProxy[] { proxies[index]}, stream, RefactoringDescriptor.NONE, true, null); - refactoring.setAttribute("refactoring" + count, stream.toString("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$ + refactoring.setAttribute("refactoring" + count, stream.toString(StandardCharsets.UTF_8)); //$NON-NLS-1$ } catch (CoreException exception) { JavaPlugin.log(exception); - } catch (UnsupportedEncodingException exception) { - Assert.isTrue(false); } } } finally { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/ModifyDialog.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/ModifyDialog.java index acd64165d34..9b2f36891a2 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/ModifyDialog.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/ModifyDialog.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; @@ -950,7 +951,7 @@ protected int getIndent(PreferenceTreeNode parent) { protected void saveState() { try (ByteArrayOutputStream out= new ByteArrayOutputStream()) { writeExpansionState(fRoot, out); - fDialogSettings.put(fKeyPreferenceTreeExpansion, out.toString("UTF-8")); //$NON-NLS-1$ + fDialogSettings.put(fKeyPreferenceTreeExpansion, out.toString(StandardCharsets.UTF_8)); } catch (IOException e) { throw new AssertionError(e); } @@ -973,7 +974,7 @@ protected void restoreExpansionState() { String treeState= fDialogSettings.get(fKeyPreferenceTreeExpansion); if (treeState == null) return; - try (ByteArrayInputStream in= new ByteArrayInputStream(treeState.getBytes("UTF-8"))) { //$NON-NLS-1$ + try (ByteArrayInputStream in= new ByteArrayInputStream(treeState.getBytes(StandardCharsets.UTF_8))) { fScrolledPageContent.setReflow(false); readExpansionState(fRoot, in); fScrolledPageContent.setReflow(true); @@ -1617,7 +1618,7 @@ private String doGetPreviewCode(PreferenceTreeNode node) { protected void loadPreviews(String previewFile) { String resource= "/preview/" + previewFile; //$NON-NLS-1$ - try (Scanner s= new Scanner(getClass().getResourceAsStream(resource), "UTF-8")) { //$NON-NLS-1$ + try (Scanner s= new Scanner(getClass().getResourceAsStream(resource), StandardCharsets.UTF_8)) { fPreviewSources= s.useDelimiter("\\A").next(); //$NON-NLS-1$ } }