From 7a8141cdc02312eb66905e278c73f4c62690e54c Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Tue, 28 Mar 2023 17:39:06 +0200 Subject: [PATCH] Fix warnings in snippeteditor code and re-generate snippetsupport.jar - updated line reference to actual one - fixed deprecated warnings after Java 17 update - fixed resource leak warnings after Java 17 update - re-generated snippetsupport.jar See - https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/210 - https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/217 --- .../debug/ui/snippeteditor/ScrapbookMain.java | 31 ++++++++---------- org.eclipse.jdt.debug.ui/snippetsupport.jar | Bin 3690 -> 3536 bytes .../ui/snippeteditor/JavaSnippetEditor.java | 8 ++--- .../ui/snippeteditor/ScrapbookLauncher.java | 7 ++-- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/org.eclipse.jdt.debug.ui/Snippet Support/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookMain.java b/org.eclipse.jdt.debug.ui/Snippet Support/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookMain.java index 5b8359ee8a..23b6612970 100644 --- a/org.eclipse.jdt.debug.ui/Snippet Support/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookMain.java +++ b/org.eclipse.jdt.debug.ui/Snippet Support/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookMain.java @@ -14,19 +14,22 @@ package org.eclipse.jdt.internal.debug.ui.snippeteditor; +import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.security.CodeSource; import java.security.ProtectionDomain; /** * Support class for launching a snippet evaluation. *

- * CAUTION: This class gets compiled with target=jsr14, see scripts/buildExtraJAR.xml. Don't use URLClassLoader#close() or other post-1.4 APIs! + * CAUTION: This class gets compiled with target=1.7, see scripts/buildExtraJAR.xml. */ public class ScrapbookMain { @@ -40,25 +43,19 @@ public static void main(String[] args) { while (true) { try { evalLoop(urls); - } catch (ClassNotFoundException e) { - return; - } catch (NoSuchMethodException e) { - return; - } catch (InvocationTargetException e) { - return; - } catch (IllegalAccessException e) { + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | IOException e) { return; } } } - static void evalLoop(URL[] urls) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { - @SuppressWarnings("resource") - ClassLoader cl= new URLClassLoader(urls, null); - Class clazz= cl.loadClass("org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1"); //$NON-NLS-1$ - Method method= clazz.getDeclaredMethod("eval", new Class[] {Class.class}); //$NON-NLS-1$ - method.invoke(null, new Object[] {ScrapbookMain.class}); + static void evalLoop(URL[] urls) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException { + try (URLClassLoader cl = new URLClassLoader(urls, null)) { + Class clazz = cl.loadClass(JavaSnippetEditor.SCRAPBOOK_MAIN1_TYPE); + Method method = clazz.getDeclaredMethod(JavaSnippetEditor.SCRAPBOOK_MAIN1_METHOD, new Class[] { Class.class }); + method.invoke(null, new Object[] {ScrapbookMain.class}); + } } /** @@ -77,13 +74,13 @@ public static void nop() { static URL[] getClasspath(String[] urlStrings) { //The URL Strings MUST be properly encoded - //using URLEncoder...see ScrapbookLauncher for details + // using URLEncoder...see ScrapbookLauncher.getEncodedURL(File) URL[] urls= new URL[urlStrings.length + 1]; for (int i = 0; i < urlStrings.length; i++) { try { - urls[i + 1] = new URL(URLDecoder.decode(urlStrings[i])); - } catch (MalformedURLException e) { + urls[i + 1] = new URL(URLDecoder.decode(urlStrings[i], StandardCharsets.UTF_8.name())); + } catch (MalformedURLException | UnsupportedEncodingException e) { return null; } } diff --git a/org.eclipse.jdt.debug.ui/snippetsupport.jar b/org.eclipse.jdt.debug.ui/snippetsupport.jar index 2b871e717703479d6c8bc9bc901263757279b03e..22488b1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uAp#zKx{&qIP)$FxhikO+>a?;=cmIzKm~^%m^dX+aiR#KvtBBFeArjC zd|{^5g_Xr}dXDTmy3$Y9qsMOC$3;HOdg)7#t!9q_#0NrVq?3VSHToNrGEvr@_SYvI zQW^=YxH)y5${|Quad>`kTyH??pk!#A9-mG4@rlOS?Z-Zt?DRY}KNo*siss+@{|jtGD=f zS1rAV`a2r_vCS3_@7lQSXR|}cKQ`Oq<6W~W|7`XrE&teWi)mf_~&v;D0Lkbpu8~fizpL2gn~I ND)Qlyd^7+6{s5L6X3_uv diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetEditor.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetEditor.java index 28125ac806..cef941be66 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetEditor.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetEditor.java @@ -134,14 +134,14 @@ */ public class JavaSnippetEditor extends AbstractDecoratedTextEditor implements IDebugEventFilter, IEvaluationListener, IValueDetailListener { - private static final String SCRAPBOOK_MAIN1_TYPE = "org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1"; //$NON-NLS-1$ - private static final String SCRAPBOOK_MAIN1_METHOD = "eval"; //$NON-NLS-1$ + static final String SCRAPBOOK_MAIN1_TYPE = "org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1"; //$NON-NLS-1$ + static final String SCRAPBOOK_MAIN1_METHOD = "eval"; //$NON-NLS-1$ /** - * Last instruction line in org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1.eval() + * Last instruction line in org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1.eval() * method that corresponds to the code compiled and checked into org.eclipse.jdt.debug.ui/snippetsupport.jar */ - private static final int SCRAPBOOK_MAIN1_LAST_LINE = 28; + private static final int SCRAPBOOK_MAIN1_LAST_LINE = 31; public static final String IMPORTS_CONTEXT = "SnippetEditor.imports"; //$NON-NLS-1$ diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookLauncher.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookLauncher.java index 9bfd848437..7646ae8d71 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookLauncher.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookLauncher.java @@ -361,11 +361,8 @@ protected URL getEncodedURL(File file) throws MalformedURLException, Unsupported while (tokenizer.hasMoreElements()) { encoded.append(urlDelimiter); String token= tokenizer.nextToken(); - try { - encoded.append(URLEncoder.encode(token, ResourcesPlugin.getEncoding())); - } catch (UnsupportedEncodingException e) { - encoded.append(URLEncoder.encode(token, "UTF-8")); //$NON-NLS-1$ - } + // should use same encoding as org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain.getClasspath(String[]) + encoded.append(URLEncoder.encode(token, "UTF-8")); //$NON-NLS-1$ } if (file.isDirectory()) { encoded.append(urlDelimiter);