Skip to content

Static import fix#459

Merged
kelloggm merged 3 commits into
njit-jerse:mainfrom
theron-wang:static-import-fix
Jul 15, 2026
Merged

Static import fix#459
kelloggm merged 3 commits into
njit-jerse:mainfrom
theron-wang:static-import-fix

Conversation

@theron-wang

Copy link
Copy Markdown
Collaborator

Fixes:

  • Static wildcard imports are not removed if they import from a used class

@theron-wang
theron-wang requested a review from kelloggm July 15, 2026 16:16

@kelloggm kelloggm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kelloggm
kelloggm enabled auto-merge (squash) July 15, 2026 16:18
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@theron-wang, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e5f27c96-39f6-413f-a912-9e27d1c4a5b2

📥 Commits

Reviewing files that changed from the base of the PR and between 7da4c7a and b98f2e1.

📒 Files selected for processing (1)
  • src/main/java/org/checkerframework/specimin/SpeciminRunner.java
📝 Walkthrough

Walkthrough

SpeciminRunner now collects package identifiers and fully qualified type names from solved slices and generated symbol content when filtering wildcard imports. The formatter uses this combined set while continuing to bypass JDK package qualifiers. A regression test and corresponding input and expected sources cover a static wildcard import from com.example.Foo and preservation of Simple#foo().

Possibly related PRs

  • njit-jerse/specimin#458: Updates the same SpeciminRunner wildcard-import pruning logic to track fully qualified classes.

Suggested reviewers: kelloggm

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/checkerframework/specimin/SpeciminRunner.java`:
- Around line 459-491: Update getUsedPackagesAndClasses to continue processing
each compilation unit’s TypeDeclaration entries even when no package declaration
exists; record the default-package marker without returning early. In the
enumeratorResult class-name loop, also add className itself when it has no dot,
while preserving existing package and fully qualified name tracking for dotted
names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5e1d79cd-6228-4796-9791-5a0c7b31e84f

📥 Commits

Reviewing files that changed from the base of the PR and between 19acb03 and 7da4c7a.

📒 Files selected for processing (6)
  • src/main/java/org/checkerframework/specimin/SpeciminRunner.java
  • src/test/java/org/checkerframework/specimin/StaticWildcardClassImportTest.java
  • src/test/resources/staticwildcardclassimport/expected/com/example/Foo.java
  • src/test/resources/staticwildcardclassimport/expected/com/example/Simple.java
  • src/test/resources/staticwildcardclassimport/input/com/example/Foo.java
  • src/test/resources/staticwildcardclassimport/input/com/example/Simple.java

Comment on lines +459 to +491
private static Set<String> getUsedPackagesAndClasses(
SliceResult sliceResult, UnsolvedSymbolEnumeratorResult enumeratorResult) {
Set<String> usedPackagesAndClasses = new HashSet<>();
for (CompilationUnit cu : sliceResult.solvedSlice()) {
if (cu.getPackageDeclaration().isEmpty()) {
usedPackagesAndClasses.add("");
continue;
}
usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString());

for (TypeDeclaration<?> typeDecl : cu.findAll(TypeDeclaration.class)) {
String fqn = typeDecl.getFullyQualifiedName().orElse(null);

if (fqn == null) {
continue;
}

usedPackagesAndClasses.add(fqn);
}
}

for (String className : enumeratorResult.classNamesToFileContent().keySet()) {
int lastDot = className.lastIndexOf('.');
if (lastDot < 0) {
usedPackagesAndClasses.add("");
} else {
usedPackagesAndClasses.add(className.substring(0, lastDot));
usedPackagesAndClasses.add(className);
}
}
return usedPackagesAndClasses;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Fix logic that skips tracking fully-qualified names in the default package.

When a compilation unit has no package declaration (the default package), the continue statement skips the inner loop, meaning no TypeDeclarations from that file are added to the set. Similarly, for class names without a dot, className itself is not added to the set.

While Java prohibits importing types from the unnamed package—which prevents this bug from affecting the wildcard import removal directly—this logic leaves the usedPackagesAndClasses set incomplete and could lead to subtle bugs if the set is ever repurposed.

🐛 Proposed fix
   private static Set<String> getUsedPackagesAndClasses(
       SliceResult sliceResult, UnsolvedSymbolEnumeratorResult enumeratorResult) {
     Set<String> usedPackagesAndClasses = new HashSet<>();
     for (CompilationUnit cu : sliceResult.solvedSlice()) {
-      if (cu.getPackageDeclaration().isEmpty()) {
-        usedPackagesAndClasses.add("");
-        continue;
-      }
-      usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString());
+      if (cu.getPackageDeclaration().isPresent()) {
+        usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString());
+      } else {
+        usedPackagesAndClasses.add("");
+      }
 
       for (TypeDeclaration<?> typeDecl : cu.findAll(TypeDeclaration.class)) {
         String fqn = typeDecl.getFullyQualifiedName().orElse(null);
 
         if (fqn == null) {
           continue;
         }
 
         usedPackagesAndClasses.add(fqn);
       }
     }
 
     for (String className : enumeratorResult.classNamesToFileContent().keySet()) {
       int lastDot = className.lastIndexOf('.');
       if (lastDot < 0) {
         usedPackagesAndClasses.add("");
       } else {
         usedPackagesAndClasses.add(className.substring(0, lastDot));
-        usedPackagesAndClasses.add(className);
       }
+      usedPackagesAndClasses.add(className);
     }
     return usedPackagesAndClasses;
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static Set<String> getUsedPackagesAndClasses(
SliceResult sliceResult, UnsolvedSymbolEnumeratorResult enumeratorResult) {
Set<String> usedPackagesAndClasses = new HashSet<>();
for (CompilationUnit cu : sliceResult.solvedSlice()) {
if (cu.getPackageDeclaration().isEmpty()) {
usedPackagesAndClasses.add("");
continue;
}
usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString());
for (TypeDeclaration<?> typeDecl : cu.findAll(TypeDeclaration.class)) {
String fqn = typeDecl.getFullyQualifiedName().orElse(null);
if (fqn == null) {
continue;
}
usedPackagesAndClasses.add(fqn);
}
}
for (String className : enumeratorResult.classNamesToFileContent().keySet()) {
int lastDot = className.lastIndexOf('.');
if (lastDot < 0) {
usedPackagesAndClasses.add("");
} else {
usedPackagesAndClasses.add(className.substring(0, lastDot));
usedPackagesAndClasses.add(className);
}
}
return usedPackagesAndClasses;
}
private static Set<String> getUsedPackagesAndClasses(
SliceResult sliceResult, UnsolvedSymbolEnumeratorResult enumeratorResult) {
Set<String> usedPackagesAndClasses = new HashSet<>();
for (CompilationUnit cu : sliceResult.solvedSlice()) {
if (cu.getPackageDeclaration().isPresent()) {
usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString());
} else {
usedPackagesAndClasses.add("");
}
for (TypeDeclaration<?> typeDecl : cu.findAll(TypeDeclaration.class)) {
String fqn = typeDecl.getFullyQualifiedName().orElse(null);
if (fqn == null) {
continue;
}
usedPackagesAndClasses.add(fqn);
}
}
for (String className : enumeratorResult.classNamesToFileContent().keySet()) {
int lastDot = className.lastIndexOf('.');
if (lastDot < 0) {
usedPackagesAndClasses.add("");
} else {
usedPackagesAndClasses.add(className.substring(0, lastDot));
}
usedPackagesAndClasses.add(className);
}
return usedPackagesAndClasses;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/checkerframework/specimin/SpeciminRunner.java` around lines
459 - 491, Update getUsedPackagesAndClasses to continue processing each
compilation unit’s TypeDeclaration entries even when no package declaration
exists; record the default-package marker without returning early. In the
enumeratorResult class-name loop, also add className itself when it has no dot,
while preserving existing package and fully qualified name tracking for dotted
names.

@theron-wang theron-wang mentioned this pull request Jul 15, 2026
@kelloggm
kelloggm merged commit f68eaaa into njit-jerse:main Jul 15, 2026
3 checks passed
@theron-wang
theron-wang deleted the static-import-fix branch July 15, 2026 16:47
theron-wang added a commit that referenced this pull request Jul 15, 2026
Fixes:
* Constructors are preserved/created with a minimal super call when its
superclass does not have a parameterless constructor

Once #459 merges and this PR is reviewed, set base to branch main and
let the CI run again.

(I based this off of static-import-fix instead of main because I figured
it would avoid merge conflicts down the line once this is merged)

---------

Co-authored-by: Martin Kellogg <martin.kellogg@njit.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants