From 723c7ffc43ec4cabd66109db17d596ac7f97396a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 11 Jun 2024 09:58:54 +0200 Subject: [PATCH] Prevent NPE when no artifact repository is given Currently RawMirrorRequest can fail if no repository is given in the descriptor and it want to log a message. P2 should be gracefully in this case and simply report the location as being unknown. --- .../META-INF/MANIFEST.MF | 2 +- .../p2/artifact/repository/RawMirrorRequest.java | 15 ++++++++++++++- .../feature.xml | 2 +- .../feature.xml | 2 +- .../org.eclipse.equinox.server.p2/feature.xml | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF index bee0aa8803..5df6b28dc4 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.artifact.repository;singleton:=true -Bundle-Version: 1.5.400.qualifier +Bundle-Version: 1.5.500.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.artifact.repository.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java index 5f1939ea05..932f717554 100644 --- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java +++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/RawMirrorRequest.java @@ -16,6 +16,7 @@ package org.eclipse.equinox.internal.p2.artifact.repository; import java.io.OutputStream; +import java.net.URI; import java.util.Collection; import java.util.Collections; import org.eclipse.core.runtime.*; @@ -95,7 +96,7 @@ protected IStatus getArtifact(IArtifactDescriptor artifactDescriptor, OutputStre if (steps.isEmpty()) { LogHelper.log(new Status(IStatus.WARNING, Activator.ID, NLS.bind(Messages.noDigestAlgorithmToVerifyDownload, artifactDescriptor.getArtifactKey(), - artifactDescriptor.getRepository().getLocation()))); + getLocation(artifactDescriptor)))); } ProcessingStep[] stepArray = steps.toArray(new ProcessingStep[steps.size()]); // TODO should probably be using createAndLink here @@ -105,4 +106,16 @@ protected IStatus getArtifact(IArtifactDescriptor artifactDescriptor, OutputStre subMon.setWorkRemaining(1); return getSourceRepository().getRawArtifact(artifactDescriptor, destination, subMon.split(1)); } + + private String getLocation(IArtifactDescriptor artifactDescriptor) { + IArtifactRepository repository = artifactDescriptor.getRepository(); + if (repository == null) { + return ""; //$NON-NLS-1$ + } + URI loc = repository.getLocation(); + if (loc == null) { + return ""; //$NON-NLS-1$ + } + return loc.toASCIIString(); + } } diff --git a/features/org.eclipse.equinox.p2.core.feature/feature.xml b/features/org.eclipse.equinox.p2.core.feature/feature.xml index 0fea4df593..a3ec151be6 100644 --- a/features/org.eclipse.equinox.p2.core.feature/feature.xml +++ b/features/org.eclipse.equinox.p2.core.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/features/org.eclipse.equinox.p2.extras.feature/feature.xml b/features/org.eclipse.equinox.p2.extras.feature/feature.xml index a8937c9fc4..5abbd489b6 100644 --- a/features/org.eclipse.equinox.p2.extras.feature/feature.xml +++ b/features/org.eclipse.equinox.p2.extras.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/features/org.eclipse.equinox.server.p2/feature.xml b/features/org.eclipse.equinox.server.p2/feature.xml index 0761830750..2043985164 100644 --- a/features/org.eclipse.equinox.server.p2/feature.xml +++ b/features/org.eclipse.equinox.server.p2/feature.xml @@ -2,7 +2,7 @@