Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven Workspace Reader 'findArtifact' should not return cached Maven projects (?) #454

Closed
vrubezhny opened this issue Jul 26, 2023 · 3 comments · Fixed by #456 or #457
Closed

Maven Workspace Reader 'findArtifact' should not return cached Maven projects (?) #454

vrubezhny opened this issue Jul 26, 2023 · 3 comments · Fixed by #456 or #457
Assignees

Comments

@vrubezhny
Copy link
Contributor

The Maven Workspace Reader probably should not acquire and try returning Maven projects collected in Maven Projects Cache ...

First of all, the MavenLemminxWorkspaceReader.findArtifact(Artifact) method overrides org.eclipse.aether.repository.WorkspaceReader.findArtifact(Artifact) and aims to return an information on Workspace artifacts (projects), not all the dependency artifacts (collected in Maven Projects Cache).

Secondly, Maven Resolver starts acquiring different sources on early stages, which sometimes causes a Concurrent Modification -like exceptions to appear when getting the list of projects collected in Maven Projects Cache (as the cache is actively building at stat up) see #449 and the following stacktrace, clearly showing a loop like "MavenProjectCache.parseAndCache -> .DefaultArtifactResolver.resolve -> MavenLemminxWorkspaceReader.findArtifact -> MavenProjectCache.getProjects` which causes a CME-like exceptions:

java.lang.IllegalStateException: End size 911 is less than fixed size 915
	at java.base/java.util.stream.Nodes$FixedNodeBuilder.end(Nodes.java:1232)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575)
	at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
	at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
	at org.eclipse.lemminx.extensions.maven.MavenLemminxWorkspaceReader.findArtifact(MavenLemminxWorkspaceReader.java:225)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:343)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:259)
	at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:352)
	at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:182)
	at org.apache.maven.project.DefaultProjectBuilder.resolveDependencies(DefaultProjectBuilder.java:224)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:202)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:123)
	at org.apache.maven.project.DefaultProjectBuilder.initParent(DefaultProjectBuilder.java:897)
	at org.apache.maven.project.DefaultProjectBuilder.initProject(DefaultProjectBuilder.java:674)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:188)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:123)
	at org.apache.maven.project.DefaultProjectBuilder.initParent(DefaultProjectBuilder.java:897)
	at org.apache.maven.project.DefaultProjectBuilder.initProject(DefaultProjectBuilder.java:674)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:188)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:123)
	at org.apache.maven.project.DefaultProjectBuilder.initParent(DefaultProjectBuilder.java:897)
	at org.apache.maven.project.DefaultProjectBuilder.initProject(DefaultProjectBuilder.java:674)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:188)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:139)
	at org.eclipse.lemminx.extensions.maven.MavenProjectCache.parseAndCache(MavenProjectCache.java:164)
	at org.eclipse.lemminx.extensions.maven.MavenProjectCache.parseAndCache(MavenProjectCache.java:251)
	at org.eclipse.lemminx.extensions.maven.MavenProjectCache.check(MavenProjectCache.java:131)
	at org.eclipse.lemminx.extensions.maven.MavenProjectCache.getLastSuccessfulMavenProject(MavenProjectCache.java:106)
	at org.eclipse.lemminx.extensions.maven.MavenLemminxExtension.lambda$getCurrentWorkspaceProjects$9(MavenLemminxExtension.java:628)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575)
	at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
	at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
	at org.eclipse.lemminx.extensions.maven.MavenLemminxExtension.getCurrentWorkspaceProjects(MavenLemminxExtension.java:629)
	at org.eclipse.lemminx.extensions.maven.participants.completion.MavenCompletionParticipant.internalCollectWorkspaceArtifacts(MavenCompletionParticipant.java:1244)
	at org.eclipse.lemminx.extensions.maven.participants.completion.MavenCompletionParticipant.onXMLContent(MavenCompletionParticipant.java:351)
	at org.eclipse.lemminx.services.XMLCompletions.collectInsideContent(XMLCompletions.java:798)
	at org.eclipse.lemminx.services.XMLCompletions.doComplete(XMLCompletions.java:226)
	at org.eclipse.lemminx.services.XMLLanguageService.doComplete(XMLLanguageService.java:171)
	at org.eclipse.lemminx.XMLTextDocumentService.lambda$completion$3(XMLTextDocumentService.java:264)
	at org.eclipse.lemminx.commons.ModelTextDocuments.lambda$computeModelAsync$0(ModelTextDocuments.java:118)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Also, by adding additional logging, I traced the results returning by MavenLemminxWorkspaceReader.findArtifact and this has shown that NOT A SINGLE non-null Maven project file was found from the Maven Projects Cache for my test workspace with Tycho project imported into it. Every non-null resulting Maven project file returned was representing an Artifact of the given Tycho project and was found by searching in Artifacts loaded n Maven Workspace Reader after the initialization. All the null-results were returned for the projects collected in Maven Projects Cache where most of the cached projects are not part of the Workspace.

Giver all this I believe that the Maven Workspace Reader API methods should not try/acquire/read any Maven Project data from the Maven Projects Cache and any try to do that is erroneous and should be avoided.

@mickaelistria
Copy link
Contributor

The MavenProjectCache is pretty useful when working on a single file. It prevents from having to rebuild the model all the time according to the content of the working copy.
Having it used by the WorkspaceReader is supposed to give a very fast feedback loop: when editing a parent pom, some errors can then be shown on the children pom. However, such feedback is most likely sufficient when the file is saved, so the WorkspaceReader could bypass the project cache.
I believe there are numerous tests on this topic to cover the important cases, so if tests pass, then it's most likely OK to change things.

Overall, the projectCache should probably be internal, and renamed to something like "projectsWorkingCopy" and only contain the project that are being edited; and for other cases, the workspaceReader should be queried.

@vrubezhny
Copy link
Contributor Author

vrubezhny commented Jul 26, 2023

Overall, the projectCache should probably be internal, ... and only contain the project that are being edited; and for other cases, the workspaceReader should be queried.

In reality projectCache, f.i. for Tychio project added to Workspace, contains >900 Maven Projects, and most of them have project.getFile() == null :see findArtifact.log - and those Artifacts are not the ones came from Workspace

At the same workspaceReader contains all the Artifacts included to the Workspace which fully suits the findArtifact API needs

@vrubezhny
Copy link
Contributor Author

The same thing happens for MavenLemminxWorkspaceReader.findVersions:

[Error - 1:44:41 AM] Jul 27, 2023 01:44:41 org.eclipse.lemminx.extensions.maven.MavenProjectCache parseAndCache()
Message: null
java.util.ConcurrentModificationException
	at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1784)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at org.eclipse.lemminx.extensions.maven.MavenLemminxWorkspaceReader.findVersions(MavenLemminxWorkspaceReader.java:265)
	at org.apache.maven.repository.internal.DefaultVersionResolver.resolveVersion(DefaultVersionResolver.java:164)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:325)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:259)
	at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:352)
	at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:182)
	at org.apache.maven.project.DefaultProjectBuilder.resolveDependencies(DefaultProjectBuilder.java:224)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:202)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:139)
	at org.eclipse.lemminx.extensions.maven.MavenProjectCache.parseAndCache(MavenProjectCache.java:164)
	at org.eclipse.lemminx.extensions.maven.MavenProjectCache.parseAndCache(MavenProjectCache.java:251)
	at org.eclipse.lemminx.extensions.maven.MavenProjectCache.check(MavenProjectCache.java:131)
	at org.eclipse.lemminx.extensions.maven.MavenProjectCache.getLastSuccessfulMavenProject(MavenProjectCache.java:106)
	at org.eclipse.lemminx.extensions.maven.MavenLemminxExtension.lambda$getCurrentWorkspaceProjects$9(MavenLemminxExtension.java:628)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575)
	at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
	at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
	at org.eclipse.lemminx.extensions.maven.MavenLemminxExtension.getCurrentWorkspaceProjects(MavenLemminxExtension.java:629)
	at org.eclipse.lemminx.extensions.maven.participants.completion.MavenCompletionParticipant.internalCollectWorkspaceArtifacts(MavenCompletionParticipant.java:1237)
	at org.eclipse.lemminx.extensions.maven.participants.completion.MavenCompletionParticipant.onXMLContent(MavenCompletionParticipant.java:303)
	at org.eclipse.lemminx.services.XMLCompletions.collectInsideContent(XMLCompletions.java:798)
	at org.eclipse.lemminx.services.XMLCompletions.doComplete(XMLCompletions.java:226)
	at org.eclipse.lemminx.services.XMLLanguageService.doComplete(XMLLanguageService.java:171)
	at org.eclipse.lemminx.XMLTextDocumentService.lambda$completion$3(XMLTextDocumentService.java:264)
	at org.eclipse.lemminx.commons.ModelTextDocuments.lambda$computeModelAsync$0(ModelTextDocuments.java:118)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

@vrubezhny vrubezhny reopened this Jul 27, 2023
vrubezhny added a commit to vrubezhny/lemminx-maven that referenced this issue Jul 27, 2023
…projects (?) eclipse-lemminx#454

This fixes the similar exception for 'MavenLemminxWorkspaceReader.findVersions'

Fixes: eclipse-lemminx#454
vrubezhny added a commit that referenced this issue Jul 27, 2023
…projects (?) #454

This fixes the similar exception for 'MavenLemminxWorkspaceReader.findVersions'

Fixes: #454
@vrubezhny vrubezhny self-assigned this Jul 28, 2023
@vrubezhny vrubezhny moved this to Done in Java Tooling Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants