Bug 481443 - CLassCastException While Downloading Repository that loads
fine in RCP target

- Add instanceof check
- make sure RTE does not interrupt exception flow

Change-Id: I071b339f985e73adc4cc8aecfa0b20e063b285a9
Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
index 1fc6599..b2f0e90 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.equinox.p2.metadata.repository;singleton:=true
-Bundle-Version: 1.3.400.qualifier
+Bundle-Version: 1.3.500.qualifier
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
 Export-Package: org.eclipse.equinox.internal.p2.metadata.repository;
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/pom.xml b/bundles/org.eclipse.equinox.p2.metadata.repository/pom.xml
index 97ec7e6..c112723 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/pom.xml
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/pom.xml
@@ -19,6 +19,6 @@
   </parent>
 	<groupId>org.eclipse.equinox</groupId>
 	<artifactId>org.eclipse.equinox.p2.metadata.repository</artifactId>
-	<version>1.3.400-SNAPSHOT</version>
+	<version>1.3.500-SNAPSHOT</version>
 	<packaging>eclipse-plugin</packaging>
 </project>
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java
index 06707e8..e679ea6 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/LocalMetadataRepository.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2007, 2018 IBM Corporation and others.
+ *  Copyright (c) 2007, 2020 IBM Corporation and others.
  *
  *  This program and the accompanying materials
  *  are made available under the terms of the Eclipse Public License 2.0
@@ -11,6 +11,7 @@
  *  Contributors:
  *     IBM Corporation - initial API and implementation
  *     Prashant Deva - Bug 194674 [prov] Provide write access to metadata repository
+ *    Christoph Läubrich - Bug 481443 - CLassCastException While Downloading Repository that loads fine in RCP target
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.metadata.repository;
 
@@ -296,11 +297,14 @@
 					return oldValue;
 				save();
 			}
-			//force repository manager to reload this repository because it caches properties
-			MetadataRepositoryManager manager = (MetadataRepositoryManager) getProvisioningAgent()
+			IMetadataRepositoryManager manager = getProvisioningAgent()
 					.getService(IMetadataRepositoryManager.class);
-			if (manager.removeRepository(getLocation()))
-				manager.addRepository(this);
+			if (manager instanceof MetadataRepositoryManager) {
+				// force repository manager to reload this repository because it caches
+				// properties
+				if (manager.removeRepository(getLocation()))
+					((MetadataRepositoryManager) manager).addRepository(this);
+			}
 			return oldValue;
 		} finally {
 			if (monitor != null)
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.updatesite/META-INF/MANIFEST.MF
index 9186c37..115a12a 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.updatesite/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.equinox.p2.updatesite;singleton:=true
-Bundle-Version: 1.1.400.qualifier
+Bundle-Version: 1.1.500.qualifier
 Bundle-Activator: org.eclipse.equinox.internal.p2.updatesite.Activator
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/pom.xml b/bundles/org.eclipse.equinox.p2.updatesite/pom.xml
index e398c7f..bc731ab 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/pom.xml
+++ b/bundles/org.eclipse.equinox.p2.updatesite/pom.xml
@@ -9,6 +9,6 @@
   </parent>
   <groupId>org.eclipse.equinox</groupId>
   <artifactId>org.eclipse.equinox.p2.updatesite</artifactId>
-  <version>1.1.400-SNAPSHOT</version>
+  <version>1.1.500-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java
index 815d8ba..97f8059 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java
+++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2017 IBM Corporation and others.
+ * Copyright (c) 2008, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,7 @@
  *     Ray Braithwood (ray@genuitec.com) - fix for bug 220605
  *     Code 9 - ongoing development
  *     Sonatype, Inc. - transport split
+ *     Christoph Läubrich - Bug 481443 - CLassCastException While Downloading Repository that loads fine in RCP target
  *******************************************************************************/
 package org.eclipse.equinox.internal.p2.updatesite.metadata;
 
@@ -60,7 +61,11 @@
 		try {
 			initializeRepository(repository, location, monitor);
 		} catch (Exception e) {
-			resetCache(repository);
+			try {
+				resetCache(repository);
+			} catch (RuntimeException rte) {
+				e.addSuppressed(rte);
+			}
 			if (e instanceof ProvisionException)
 				throw (ProvisionException) e;
 			if (e instanceof OperationCanceledException)