openrewrite / openrewrite/rewrite

Classpath pollution for `JavaParser#classpathFromResource`

Open
#5,751 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What version of OpenRewrite are you using?

OpenRewrite/rewrite main branch

How are you running OpenRewrite?

  • Via test harness, see #5752

What is the smallest, simplest way to reproduce the problem?

Have a type table created with 2 dependencies for instancejavax.servlet:javax.servlet-api:4.+ and jakarta.servlet:jakarta.servlet-api:6.+

What did you expect to see?

JavaParser.fromJavaVersion()
      .classpathFromResources(new InMemoryExecutionContext(), "jakarta.servlet-api")
      .build()
      .parse("import javax.servlet.ServletContext; class Test {}");
// should contain a ParseError

What did you see instead?

snippet above has a J.CompilationUnit.

What is the full stack trace of any errors you encountered?

none, all fine.

Are you interested in contributing a fix to OpenRewrite?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at JavaParser#classpathFromResource and reproduce the case through the test harness referenced in #5752, using both javax.servlet-api:4.+ and jakarta.servlet-api:6.+ in the type table. Done means parsing the javax.servlet import with only jakarta.servlet-api requested produces a ParseError rather than a compilation unit.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.