From 88475d3c18656db72b4e76e81e8f0d61b3c3b82e Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Thu, 10 Oct 2024 01:42:20 +0200 Subject: [PATCH] Remove ZipError usage which is dead code since JDK 9 (JDK-8336843). - CachingArchive catches Exception from now on which seems to be the safest approach - removed the ZipError handler from NexusRepositoryIndexerImpl since the section is inside a repo mutex and MutexExceptions are already handled --- .../java/source/parsing/CachingArchive.java | 6 ++---- .../indexer/NexusRepositoryIndexerImpl.java | 20 ++++++++----------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchive.java b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchive.java index 9be20747b866..59307c8d7ad3 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchive.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingArchive.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; @@ -39,7 +38,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.ZipEntry; -import java.util.zip.ZipError; import java.util.zip.ZipFile; import javax.lang.model.SourceVersion; import javax.tools.JavaFileObject; @@ -363,12 +361,12 @@ private Map createMap(File file ) throws IOException { entry = e.nextElement(); } catch (IllegalArgumentException iae) { throw new IOException(iae); - } catch (ZipError ze) { + } catch (Exception ex) { // the JAR may be corrupted somehow; no further entry read // will probably succeed, so just skip the rest of the jar. Exceptions.printStackTrace( Exceptions.attachLocalizedMessage( - Exceptions.attachSeverity(ze, Level.WARNING), + Exceptions.attachSeverity(ex, Level.WARNING), Bundle.ERR_CorruptedZipFile(file))); break; } diff --git a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java index 93580fda9da1..bffe61e34114 100644 --- a/java/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java +++ b/java/maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java @@ -44,7 +44,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; -import java.util.zip.ZipError; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; @@ -886,10 +885,8 @@ public void updateIndexWithArtifacts(final RepositoryInfo repo, final Collection BooleanQuery bq = new BooleanQuery.Builder() .add(new BooleanClause(new PrefixQuery(new Term(ArtifactInfo.UINFO, id)), BooleanClause.Occur.MUST)) .build(); - IteratorSearchResponse response = repeatedPagedSearch(bq, indexingContext, MAX_RESULT_COUNT); - add = response == null || response.getTotalHitsCount() == 0; - if (response != null) { - response.close(); + try (IteratorSearchResponse response = repeatedPagedSearch(bq, indexingContext, MAX_RESULT_COUNT)) { + add = response == null || response.getTotalHitsCount() == 0; } } if (add) { @@ -903,17 +900,16 @@ public void updateIndexWithArtifacts(final RepositoryInfo repo, final Collection } } - try { - indexer.addArtifactsToIndex(artifactContexts, indexingContext); - storeGroupCache(repo, indexingContext); - } catch (ZipError err) { - LOGGER.log(Level.INFO, "#230581 concurrent access to local repository file. Skipping..", err); - } + indexer.addArtifactsToIndex(artifactContexts, indexingContext); + storeGroupCache(repo, indexingContext); return null; }); } catch (MutexException ex) { - Exceptions.printStackTrace(ex); + List sample = artifacts.stream().limit(5).toList(); + LOGGER.log(Level.WARNING, + "Unable to update index with artifact(s): " + sample + + (artifacts.size() > sample.size() ? (" +" + (artifacts.size() - sample.size()) + " more") : ""), ex); } catch (NullPointerException x) { LOGGER.log(Level.INFO, "#201057", x); }