Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 481443

Summary: CLassCastException While Downloading Repository that loads fine in RCP target
Product: [Eclipse Project] Equinox Reporter: Mark Leone <mleone>
Component: p2Assignee: Christoph Laeubrich <laeubi>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: arcanefoam, christian.dietrich.opensource, david_williams, flo, jan.sievers, kravets.dev, laeubi, mistria
Version: unspecified   
Target Milestone: 4.19 M3   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/c/equinox/rt.equinox.p2/+/173988
https://git.eclipse.org/c/equinox/rt.equinox.p2.git/commit/?id=08eece6cff8f1a274c87e0ccc92542c0cc4907a7
https://bugs.eclipse.org/bugs/show_bug.cgi?id=571195
Whiteboard:

Description Mark Leone CLA 2015-11-04 14:13:57 EST
When I run a Maven build that includes the repo location http://hge.javaforge.com/mercurialeclipse-snapshots Tycho fails after throwing a ClassCastException. This site loads correctly in an RCP target, and I can navigate to it with the Eclipse repository browser. This is reproducile 100% of the times for me.

Stack Trace when running mvn -e -X clean install

[INFO] Fetching site.xml from http://hge.javaforge.com/mercurialeclipse-snapshots/ (0B at 0B/s)
!SESSION 2015-11-04 14:09:37.351 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_51
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  -eclipse.keyring /tmp/tycho4094917301749271388secure_storage
Command-line arguments:  -eclipse.keyring /tmp/tycho4094917301749271388secure_storage -debug -consoleLog

!ENTRY org.eclipse.equinox.p2.metadata.repository 4 0 2015-11-04 14:09:37.351
!MESSAGE Unexpected error loading extension: org.eclipse.equinox.p2.updatesite.metadataRepository
!STACK 0
java.lang.ClassCastException: org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast to org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager
	at org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository.setProperty(LocalMetadataRepository.java:325)
	at org.eclipse.equinox.p2.repository.spi.AbstractRepository.setProperty(AbstractRepository.java:189)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.resetCache(UpdateSiteMetadataRepositoryFactory.java:81)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.load(UpdateSiteMetadataRepositoryFactory.java:61)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.factoryLoad(MetadataRepositoryManager.java:57)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:768)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:668)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.loadRepository(MetadataRepositoryManager.java:96)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:61)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:53)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.loadMetadataRepository(TargetPlatformFactoryImpl.java:298)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.gatherExternalInstallableUnits(TargetPlatformFactoryImpl.java:270)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:176)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:128)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:1)
	at org.eclipse.tycho.p2.manager.ReactorRepositoryManagerImpl.computePreliminaryTargetPlatform(ReactorRepositoryManagerImpl.java:84)
	at org.eclipse.tycho.p2.resolver.P2DependencyResolver.computePreliminaryTargetPlatform(P2DependencyResolver.java:223)
	at org.eclipse.tycho.core.resolver.DefaultTychoResolver.resolveProject(DefaultTychoResolver.java:109)
	at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead(TychoMavenLifecycleParticipant.java:95)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:266)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR] Internal error: java.lang.RuntimeException: Failed to load p2 repository with ID 'MercurialEclipse' from location http://hge.javaforge.com/mercurialeclipse-snapshots/: No repository found at http://hge.javaforge.com/mercurialeclipse-snapshots. -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: Failed to load p2 repository with ID 'MercurialEclipse' from location http://hge.javaforge.com/mercurialeclipse-snapshots/
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:121)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.RuntimeException: Failed to load p2 repository with ID 'MercurialEclipse' from location http://hge.javaforge.com/mercurialeclipse-snapshots/
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.loadMetadataRepository(TargetPlatformFactoryImpl.java:302)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.gatherExternalInstallableUnits(TargetPlatformFactoryImpl.java:270)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:176)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:128)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:1)
	at org.eclipse.tycho.p2.manager.ReactorRepositoryManagerImpl.computePreliminaryTargetPlatform(ReactorRepositoryManagerImpl.java:84)
	at org.eclipse.tycho.p2.resolver.P2DependencyResolver.computePreliminaryTargetPlatform(P2DependencyResolver.java:223)
	at org.eclipse.tycho.core.resolver.DefaultTychoResolver.resolveProject(DefaultTychoResolver.java:109)
	at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead(TychoMavenLifecycleParticipant.java:95)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:266)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	... 11 more
Caused by: org.eclipse.equinox.p2.core.ProvisionException: No repository found at http://hge.javaforge.com/mercurialeclipse-snapshots.
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.fail(AbstractRepositoryManager.java:395)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:692)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.loadRepository(MetadataRepositoryManager.java:96)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:61)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:53)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.loadMetadataRepository(TargetPlatformFactoryImpl.java:298)
	... 22 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/InternalErrorException
Comment 1 Jan Sievers CLA 2015-11-05 04:13:03 EST
looks like you have two different tycho versions -> two different p2 versions configured in your reactor

make sure all modules use the same tycho version (double-check using effective pom)
Comment 2 Mark Leone CLA 2015-11-06 10:33:44 EST
Why do you say I have two different maven versions? I saw that as a possible cause in my research before posting a bug report, and I was pretty sure I had only one version specified. Maybe I was mistaken; but I don't see anything in what I posted that indicates two tycho versions in the reactor.

I think the problem was caused by the mercurialeclipse site. Apparently it's not a p2 update site. Perhaps a more accurate error message would be helpful, but otherwise this seems to not be a problem with tycho.

I tried to enter a bug at the mercurialeclipse site, but the site is broken, doesn't grant the privilege to post a bug after creating an account and logging in, as advertised.
Comment 3 Jan Sievers CLA 2015-11-06 11:00:24 EST
(In reply to Mark Leone from comment #2)
> Why do you say I have two different maven versions? I saw that as a possible
> cause in my research before posting a bug report, and I was pretty sure I
> had only one version specified. Maybe I was mistaken; but I don't see
> anything in what I posted that indicates two tycho versions in the reactor.

I was reading this:

java.lang.ClassCastException: org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast to org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager

this is typically what happened with multiple Tycho versions used, see bug 386490 

but maybe it's another log entry which is unrelated to your problem with old-style update site 

http://hge.javaforge.com/mercurialeclipse-snapshots/site.xml

AFAIK p2 support for old style update sites is limited. If the original authors of the update site can't be contacted, as a workaround you can mirror and convert to the (not-so) new p2 metadata format with [1]

[1] https://wiki.eclipse.org/Tycho/Additional_Tools#publish-features-and-bundles_goal
Comment 4 Mark Leone CLA 2015-11-06 17:05:54 EST
Thanks for the tip on using the p2-extras and antrun plugins to create a p2 repo from the old style repo. Is there any documentation that you know of to show a use of it in the context of a project? It seems straightforward, but after 3 hours+ trying and searching, I can't get Maven to even recognize the plugin is being invoked (although I see Maven download it).

I added the plugin declarations to a pom file with eclipse-repository packaging, and I reference that module first in the parent pom that I'm running the build from. But the local repo does not get created (not even the target directory), and there is no error except the build fails because it can't find the resource from the repo I was trying to mirror. Really, the build behaves as if I never added any reference to those plugins.
Comment 5 David Williams CLA 2015-11-06 20:58:04 EST
(In reply to Mark Leone from comment #4)
> Thanks for the tip on using the p2-extras and antrun plugins to create a p2
> repo from the old style repo. Is there any documentation that you know of to
> show a use of it in the context of a project? It seems straightforward, but
> after 3 hours+ trying and searching, I can't get Maven to even recognize the
> plugin is being invoked (although I see Maven download it).
> 
> I added the plugin declarations to a pom file with eclipse-repository
> packaging, and I reference that module first in the parent pom that I'm
> running the build from. But the local repo does not get created (not even
> the target directory), and there is no error except the build fails because
> it can't find the resource from the repo I was trying to mirror. Really, the
> build behaves as if I never added any reference to those plugins.

I'm only skim reading your bug, but if you haven't yet, you might try just doing the publish-features-and-bundles goal in a whole separate job/run, and see if you can get that to work. I am not sure that goal should be should be "in" eclipse-repository packaging, if that is what you are saying. Often I hear people talking about doing this conversion in a separate job. Not sure if that is required, or just convenient, since once you have it converted, presumably would not have to do again unless they have a new release? 

Just trying to give a small hint to help with your workaround. I am no expert and, again, have just been skim reading the issues. 

But, a ClasscastException does sound like a bug. I can use eclipse Platform and install it, so don't think it is a bug in p2.
Comment 6 Florian Kolbe CLA 2017-09-12 07:28:34 EDT
I can confirm that to me
1. this occured after upgrading from 0.21.0 to 1.0.0, then down to 0.26.0
2. the problem went away after deleting local repositories .meta and .cache

java.lang.ClassCastException: org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast to org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager
Comment 7 Jan Sievers CLA 2017-09-12 09:05:56 EDT
(In reply to Florian Kolbe from comment #6)
> I can confirm that to me
> 1. this occured after upgrading from 0.21.0 to 1.0.0, then down to 0.26.0
> 2. the problem went away after deleting local repositories .meta and .cache
> 
> java.lang.ClassCastException:
> org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast
> to
> org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager

probably https://wiki.eclipse.org/Tycho/FAQ#My_build_fails_with_a_ClassCastException_of_a_Tycho_class._What_is_wrong.3F
Comment 8 Florian Kolbe CLA 2017-09-14 02:34:36 EDT
(In reply to Jan Sievers from comment #7)
> (In reply to Florian Kolbe from comment #6)
> > I can confirm that to me
> > 1. this occured after upgrading from 0.21.0 to 1.0.0, then down to 0.26.0
> > 2. the problem went away after deleting local repositories .meta and .cache
> > 
> > java.lang.ClassCastException:
> > org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast
> > to
> > org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager
> 
> probably
> https://wiki.eclipse.org/Tycho/
> FAQ#My_build_fails_with_a_ClassCastException_of_a_Tycho_class._What_is_wrong.
> 3F

I don't think so, since version clash in the reactor is checked, which would yield errors like:
[ERROR] Several versions of tycho plugins are configured [0.21.0, 0.26.0]:

which was not the case.
Comment 9 Aleksandr Kravets CLA 2019-07-20 23:31:05 EDT
I have similar error when building product. When I run product from Eclipse, everything works without an issue, but the moment I start building it, I get this error:

[INFO] Computing target platform for MavenProject: com.iwaysoftware.integration.tools:com.iwaysoftware.adapters:8.0.4-SNAPSHOT @ /home/akravets/dev/workspaces/branch-IIT-915/com.iwaysoftware.adapters/pom.xml
[DEBUG] Using execution environment 'JavaSE-1.8' configured in Bundle-RequiredExecutionEnvironment (first entry)
[DEBUG] Adding target definition file "/home/akravets/dev/workspaces/branch-IIT-915/com.iwaysoftware.eclipse.iit.neon/neon.target"
[DEBUG] Resolving target definition content...
[INFO] Adding repository http://eclipse.jeeeyul.net/update
[INFO] Adding repository http://products.reprezen.com/swagedit/0.8.0.201906041312
[INFO] Adding repository http://boothen.github.io/Json-Eclipse-Plugin
[INFO] Fetching p2.index from http://download.eclipse.org/emf-parsley/updates/0.3/
[INFO] Fetching p2.index from http://download.eclipse.org/emf-parsley/updates/0.3/
[INFO] Adding repository http://download.eclipse.org/emf-parsley/updates/0.3
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/
[INFO] Adding repository http://download.eclipse.org/eclipse/updates/4.6
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/R-4.6-201606061100/
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/R-4.6.1-201609071200/
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/R-4.6.1-201609071200/
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/R-4.6.2-201611241400/
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/R-4.6.2-201611241400/
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/R-4.6.3-201703010400/
[INFO] Fetching p2.index from http://download.eclipse.org/eclipse/updates/4.6/R-4.6.3-201703010400/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/
[INFO] Adding repository http://download.eclipse.org/releases/neon
[INFO] Fetching p2.index from http://download.eclipse.org/technology/epp/packages/neon/
[INFO] Fetching p2.index from http://download.eclipse.org/technology/epp/packages/neon/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201705151400/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201705151400/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201703141400/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201703141400/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201703231000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201703231000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201606221000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201606221000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201609281000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201609281000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201610111000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201610111000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201612211000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/neon/201612211000/
[INFO] Fetching p2.index from http://zeus.ibi.com/builds/http4e/ (172B)
[INFO] Fetching p2.index from http://zeus.ibi.com/builds/http4e/ (172B)
[INFO] Adding repository http://zeus.ibi.com/builds/http4e
[INFO] Adding repository http://zeus.ibi.com/builds/common/4.6
[INFO] Adding repository http://zeus.ibi.com/builds/server-runtime/4.6
[INFO] Adding repository http://dadacoalition.org/yedit
[INFO] Adding repository http://download.oracle.com/otn_software/oepe/neon
!SESSION 2019-07-20 23:19:43.274 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_111
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  -eclipse.keyring /tmp/tycho5836450650644402509secure_storage
Command-line arguments:  -eclipse.keyring /tmp/tycho5836450650644402509secure_storage -debug -consoleLog

!ENTRY org.eclipse.equinox.p2.metadata.repository 4 0 2019-07-20 23:19:43.275
!MESSAGE Unexpected error loading extension: org.eclipse.equinox.p2.updatesite.metadataRepository
!STACK 0
java.lang.ClassCastException: org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast to org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager
	at org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository.setProperty(LocalMetadataRepository.java:303)
	at org.eclipse.equinox.p2.repository.spi.AbstractRepository.setProperty(AbstractRepository.java:192)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.resetCache(UpdateSiteMetadataRepositoryFactory.java:83)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.load(UpdateSiteMetadataRepositoryFactory.java:63)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.factoryLoad(MetadataRepositoryManager.java:63)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:770)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:671)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.loadRepository(MetadataRepositoryManager.java:110)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:61)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:53)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver$LoadedIULocation.loadRepository(TargetDefinitionResolver.java:288)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver$LoadedIULocation.<init>(TargetDefinitionResolver.java:282)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver$ResolverRun.addLocation(TargetDefinitionResolver.java:154)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver.resolveContentWithExceptions(TargetDefinitionResolver.java:121)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver.resolveContent(TargetDefinitionResolver.java:94)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolverService.resolveFromArguments(TargetDefinitionResolverService.java:70)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolverService.getTargetDefinitionContent(TargetDefinitionResolverService.java:60)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.resolveTargetDefinitions(TargetPlatformFactoryImpl.java:214)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:155)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:128)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:1)
	at org.eclipse.tycho.p2.manager.ReactorRepositoryManagerImpl.computePreliminaryTargetPlatform(ReactorRepositoryManagerImpl.java:84)
	at org.eclipse.tycho.p2.resolver.P2DependencyResolver.computePreliminaryTargetPlatform(P2DependencyResolver.java:224)
	at org.eclipse.tycho.core.resolver.DefaultTychoResolver.resolveProject(DefaultTychoResolver.java:110)
	at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead(TychoMavenLifecycleParticipant.java:95)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:264)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

Reading through comments here I checked suggestions and there is no mismatch between tycho versions, and as far as I can tell no old style update is used. How can I find out the real cause of these messages?
Comment 10 Christian Dietrich CLA 2020-04-20 16:07:10 EDT
i am getting similar messages

java.lang.ClassCastException: org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast to org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager
	at org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository.setProperty(LocalMetadataRepository.java:301)
	at org.eclipse.equinox.p2.repository.spi.AbstractRepository.setProperty(AbstractRepository.java:194)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.resetCache(UpdateSiteMetadataRepositoryFactory.java:84)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.load(UpdateSiteMetadataRepositoryFactory.java:63)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.factoryLoad(MetadataRepositoryManager.java:63)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:775)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:676)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.loadRepository(MetadataRepositoryManager.java:110)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:61)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:53)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver$LoadedIULocation.loadRepository(TargetDefinitionResolver.java:288)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver$LoadedIULocation.<init>(TargetDefinitionResolver.java:282)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver$ResolverRun.addLocation(TargetDefinitionResolver.java:154)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver.resolveContentWithExceptions(TargetDefinitionResolver.java:121)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver.resolveContent(TargetDefinitionResolver.java:94)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolverService.resolveFromArguments(TargetDefinitionResolverService.java:70)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolverService.getTargetDefinitionContent(TargetDefinitionResolverService.java:60)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.resolveTargetDefinitions(TargetPlatformFactoryImpl.java:214)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:155)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:128)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:1)
	at org.eclipse.tycho.p2.manager.ReactorRepositoryManagerImpl.computePreliminaryTargetPlatform(ReactorRepositoryManagerImpl.java:84)
	at org.eclipse.tycho.p2.resolver.P2DependencyResolver.computePreliminaryTargetPlatform(P2DependencyResolver.java:226)
	at org.eclipse.tycho.core.resolver.DefaultTychoResolver.resolveProject(DefaultTychoResolver.java:110)
	at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead(TychoMavenLifecycleParticipant.java:95)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:264)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Comment 11 Horacio Hoyos CLA 2020-12-09 11:35:37 EST
I went into the source code and found that 
org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository has this code on the offending line:

MetadataRepositoryManager manager = (MetadataRepositoryManager) getProvisioningAgent().getService(IMetadataRepositoryManager.class);

and in Tycho, org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager implements IMetadataRepositoryManager but does not extend MetadataRepositoryManager. 

Looking at LocalMetadataRepository, after the cast it will call:

if (manager.removeRepository(getLocation()))
  manager.addRepository(this);

Both removeRpository and addRepository are part of IMetadataRepositoryManager so the cast should be to the interface, not the implementation. This seems more of a bug in LocalMetadataRepository that in Tycho. However, not sure if this is somehting the tycho team should push to the p2 project.
Comment 12 Mickael Istria CLA 2020-12-09 12:12:43 EST
Please attach a minimal repoducer to reproduce this issue.
Please make sure this is still happening with 2.2.0-SNAPSHOT version.
Comment 13 Christoph Laeubrich CLA 2020-12-09 12:30:28 EST
I think this is an issue of P2
Comment 14 Horacio Hoyos CLA 2020-12-10 08:29:12 EST
(In reply to Mickael Istria from comment #12)
> Please attach a minimal repoducer to reproduce this issue.
> Please make sure this is still happening with 2.2.0-SNAPSHOT version.

Sorry, development constraints have me locked to Tycho 1.7. Also, this seems to be some of those hard to reproduce issues, i.e. it seems to be working now. 

So my casting investigation is what little into this issue I am able to provide for the time being.
Comment 15 Christoph Laeubrich CLA 2020-12-19 05:55:52 EST
I'm currently facing a similar issue with tycho 2.2.0-SNAPSHOT

java.lang.ClassCastException: class org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager cannot be cast to class org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager (org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @712cd5d3; org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @11c581a0)
	at org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository.setProperty(LocalMetadataRepository.java:301)
	at org.eclipse.equinox.p2.repository.spi.AbstractRepository.setProperty(AbstractRepository.java:194)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.resetCache(UpdateSiteMetadataRepositoryFactory.java:84)
	at org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory.load(UpdateSiteMetadataRepositoryFactory.java:63)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.factoryLoad(MetadataRepositoryManager.java:63)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:775)
	at org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager.loadRepository(AbstractRepositoryManager.java:676)
	at org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager.loadRepository(MetadataRepositoryManager.java:110)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:63)
	at org.eclipse.tycho.p2.remote.RemoteMetadataRepositoryManager.loadRepository(RemoteMetadataRepositoryManager.java:55)
	at org.eclipse.tycho.p2.resolver.URITargetDefinitionContent.preload(URITargetDefinitionContent.java:78)
	at org.eclipse.tycho.p2.resolver.URITargetDefinitionContent.query(URITargetDefinitionContent.java:53)
	at org.eclipse.equinox.p2.query.CompoundQueryable.getIteratorFromQueryable(CompoundQueryable.java:178)
	at org.eclipse.equinox.p2.query.CompoundQueryable.everything(CompoundQueryable.java:124)
	at org.eclipse.equinox.internal.p2.metadata.expression.RepeatableIterator$IndexProviderIterator.<init>(RepeatableIterator.java:142)
	at org.eclipse.equinox.internal.p2.metadata.expression.RepeatableIterator.create(RepeatableIterator.java:60)
	at org.eclipse.equinox.internal.p2.metadata.expression.Everything.<init>(Everything.java:39)
	at org.eclipse.equinox.internal.p2.metadata.expression.ContextExpression.createContext(ContextExpression.java:48)
	at org.eclipse.equinox.p2.query.ExpressionQuery.perform(ExpressionQuery.java:51)
	at org.eclipse.equinox.internal.p2.metadata.index.IndexProvider.query(IndexProvider.java:26)
	at org.eclipse.equinox.internal.p2.metadata.index.IndexProvider.query(IndexProvider.java:36)
	at org.eclipse.tycho.p2.resolver.InstallableUnitResolver.findUnit(InstallableUnitResolver.java:293)
	at org.eclipse.tycho.p2.resolver.InstallableUnitResolver.findUnits(InstallableUnitResolver.java:273)
	at org.eclipse.tycho.p2.resolver.InstallableUnitResolver.getRootIUs(InstallableUnitResolver.java:266)
	at org.eclipse.tycho.p2.resolver.InstallableUnitResolver.addLocation(InstallableUnitResolver.java:100)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver.resolveContentWithExceptions(TargetDefinitionResolver.java:148)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolver.resolveContent(TargetDefinitionResolver.java:106)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolverService.resolveFromArguments(TargetDefinitionResolverService.java:77)
	at org.eclipse.tycho.p2.target.TargetDefinitionResolverService.getTargetDefinitionContent(TargetDefinitionResolverService.java:68)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.resolveTargetDefinitions(TargetPlatformFactoryImpl.java:218)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:160)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:130)
	at org.eclipse.tycho.p2.target.TargetPlatformFactoryImpl.createTargetPlatform(TargetPlatformFactoryImpl.java:1)
	at org.eclipse.tycho.p2.manager.ReactorRepositoryManagerImpl.computePreliminaryTargetPlatform(ReactorRepositoryManagerImpl.java:86)
	at org.eclipse.tycho.p2.resolver.P2DependencyResolver.computePreliminaryTargetPlatform(P2DependencyResolver.java:217)
	at org.eclipse.tycho.core.resolver.DefaultTychoResolver.resolveProject(DefaultTychoResolver.java:119)
	at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.lambda$resolveProjects$0(TychoMavenLifecycleParticipant.java:118)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.resolveProjects(TychoMavenLifecycleParticipant.java:140)
	at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead(TychoMavenLifecycleParticipant.java:99)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:264)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:954)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Comment 16 Christoph Laeubrich CLA 2020-12-19 06:39:33 EST
This is really odd...

The CCE happens because of the inappropriate casting, in fact LocalMetadataRepository onyl wants to update its properties, and thus removes the repo and then adds it again via MetadataRepositoryManager private API...
... but that only the half story, actually the *loading* of the repository fails and in this case the repo is reset and this reset then triggers the code path where the CCE occurs hide the actual error...

That's also the reason why its hard to reproduce, you need to have a failing repository to be loaded, as soon it is fixed the mysterious error is gone.

I think this must be fixed at P2 level, I don't see what tycho can do here.
Comment 17 Eclipse Genie CLA 2020-12-19 06:49:47 EST
New Gerrit change created: https://git.eclipse.org/r/c/equinox/rt.equinox.p2/+/173988
Comment 19 Mickael Istria CLA 2021-01-08 03:24:44 EST
Thanks a lot Mark for report and Christoph for fixing!