Skip to content

Commit

Permalink
Fix warnings in snippeteditor code and re-generate snippetsupport.jar
Browse files Browse the repository at this point in the history
- 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
- #210
- #217
  • Loading branch information
iloveeclipse committed Mar 28, 2023
1 parent e3fd17c commit 7a8141c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* 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 {

Expand All @@ -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});
}
}

/**
Expand All @@ -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;
}
}
Expand Down
Binary file modified org.eclipse.jdt.debug.ui/snippetsupport.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7a8141c

Please sign in to comment.