From 55a5afe5892abbf520d3ce7fe1b402a4cae1d6e6 Mon Sep 17 00:00:00 2001 From: Jay Arthanareeswaran Date: Wed, 19 Feb 2025 16:44:11 +0530 Subject: [PATCH] Fix warnings due to usage of deprecated system APIs --- .../eclipse/jdt/internal/core/ClasspathEntry.java | 8 +++++--- .../eclipse/jdt/internal/core/ImportContainer.java | 4 ++-- .../org/eclipse/jdt/internal/core/JavaElement.java | 12 +++++++----- .../jdt/core/search/IJavaSearchConstants.java | 4 ++-- .../core/search/indexing/AddJarFileToIndex.java | 5 ++--- .../core/search/indexing/IIndexConstants.java | 4 ++-- .../internal/core/search/indexing/IndexManager.java | 10 ++++++++-- .../internal/core/search/processing/JobManager.java | 5 +---- 8 files changed, 29 insertions(+), 23 deletions(-) diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java index 7ffaf4140da..e183fc0f71e 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -29,6 +29,8 @@ import java.io.InputStream; import java.io.StringWriter; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Paths; import java.util.ArrayList; @@ -1780,8 +1782,8 @@ public URL getLibraryIndexLocation() { if (IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { String value = attrib.getValue(); try { - return new URL(value); - } catch (MalformedURLException e) { + return (new URI(value)).toURL(); + } catch (MalformedURLException | URISyntaxException e) { return null; } } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ImportContainer.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ImportContainer.java index 53c75011ef4..89f3d52d605 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ImportContainer.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ImportContainer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -70,7 +70,7 @@ protected char getHandleMementoDelimiter() { */ @Override public ImportDeclaration getImport(String importName) { - int index = importName.indexOf(".*"); ///$NON-NLS-1$ + int index = importName.indexOf(".*"); //$NON-NLS-1$ boolean isOnDemand = index != -1; if (isOnDemand) { importName = importName.substring(0, index); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java index 18b1344b630..1ec8793bad6 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaElement.java @@ -23,9 +23,11 @@ import java.net.ProtocolException; import java.net.SocketException; import java.net.SocketTimeoutException; +import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.net.UnknownHostException; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -749,8 +751,8 @@ protected static URL getLibraryJavadocLocation(IClasspathEntry entry) throws Jav if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { String value = attrib.getValue(); try { - return new URL(value); - } catch (MalformedURLException e) { + return (new URI(value)).toURL(); + } catch (MalformedURLException | URISyntaxException e) { throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, value)); } } @@ -819,12 +821,12 @@ protected void validateAndCache(URL baseLoc, FileNotFoundException e) throws Jav protected String getURLContents(URL baseLoc, String docUrlValue) throws JavaModelException { InputStream stream = null; JarURLConnection connection2 = null; - URL docUrl = null; + URI docUri = null; URLConnection connection = null; try { redirect: for (int i= 0; i < 5; i++) { // avoid endless redirects... - docUrl = new URL(docUrlValue); - connection = docUrl.openConnection(); + docUri = new URI(docUrlValue); + connection = docUri.toURL().openConnection(); int timeoutVal = 10000; connection.setConnectTimeout(timeoutVal); diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java index be02fa86704..3de1b9350eb 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/IJavaSearchConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2020 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -577,6 +577,6 @@ public interface IJavaSearchConstants { * in searches involving modules * @since 3.14 */ - char[] ALL_UNNAMED = "ALL-UNNAMED".toCharArray(); ////$NON-NLS-1$ + char[] ALL_UNNAMED = "ALL-UNNAMED".toCharArray(); //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java index c1a4f44ad93..ec03a4f2304 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -22,7 +22,6 @@ import java.nio.file.NoSuchFileException; import java.util.Enumeration; import java.util.zip.ZipEntry; -import java.util.zip.ZipError; import java.util.zip.ZipFile; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; @@ -281,7 +280,7 @@ public boolean execute(IProgressMonitor progressMonitor) { } monitor.exitWrite(); // free write lock } - } catch (IOException | ZipError e) { + } catch (IOException e) { if (e instanceof NoSuchFileException) { org.eclipse.jdt.internal.core.util.Util.log(Status.info("Can not index not existing zip " + this.containerPath)); //$NON-NLS-1$ } else if ("zip file is empty".equals(e.getMessage())) { //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java index 8c0286261bd..868a0897199 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -31,7 +31,7 @@ public interface IIndexConstants { char[] MODULE_DECL= "moduleDecl".toCharArray(); //$NON-NLS-1$ char[] MODULE_REF= "moduleRef".toCharArray(); //$NON-NLS-1$ char[] OBJECT = "Object".toCharArray(); //$NON-NLS-1$ - char[] MODULE_INFO = "module-info".toCharArray(); ////$NON-NLS-1$ + char[] MODULE_INFO = "module-info".toCharArray(); //$NON-NLS-1$ char[][] COUNTS= new char[][] { new char[] {'/', '0'}, new char[] {'/', '1'}, new char[] {'/', '2'}, new char[] {'/', '3'}, new char[] {'/', '4'}, new char[] {'/', '5'}, new char[] {'/', '6'}, new char[] {'/', '7'}, new char[] {'/', '8'}, new char[] {'/', '9'} diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java index 952e0d0ee64..1df27fd4036 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -21,6 +21,7 @@ import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.*; @@ -1309,7 +1310,12 @@ private void readIndexMap() { String savedSignature = DiskIndex.SIGNATURE; if (savedSignature.equals(new String(names[0]))) { for (int i = 1, l = names.length-1 ; i < l ; i+=2) { - IndexLocation indexPath = IndexLocation.createIndexLocation(new URL(new String(names[i]))); + IndexLocation indexPath = null; + try { + indexPath = IndexLocation.createIndexLocation((new URI(new String(names[i])).toURL())); + } catch (URISyntaxException e) { + // Ignore the null path and continue + } if (indexPath == null) continue; this.indexLocations.put(new Path(new String(names[i+1])), indexPath ); this.indexStates.put(indexPath, REUSE_STATE); diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/processing/JobManager.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/processing/JobManager.java index 3c8510ae76c..1f28bb2fa1f 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/processing/JobManager.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/processing/JobManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -557,9 +557,6 @@ protected IStatus run(IProgressMonitor monitor) { } catch (InterruptedException e) { // background indexing was interrupted } } - } catch (ThreadDeath e) { - // do not restart - throw e; } catch (RuntimeException|Error e) { if (getProcessingThread() != null) { // if not shutting down // log exception