Skip to content

Skip non-existent classpath entries when scanning with Reflections - #968

Merged
chadlwilson merged 4 commits into
getgauge:masterfrom
jsoizo:fix/skip-nonexistent-classpath-entries
Oct 17, 2026
Merged

chadlwilson merged 4 commits into
getgauge:masterfrom
jsoizo:fix/skip-nonexistent-classpath-entries

Conversation

@jsoizo

@jsoizo jsoizo commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

In Kotlin-only Gradle projects, the gauge Gradle plugin puts source set output dirs that were never created (e.g. build/classes/java/main, build/resources/main) on the classpath. Reflections receives them as-is, and every scan logs two stack traces per missing dir:

  • NullPointerException from the custom UrlType in ClasspathScanner (Vfs.getFile returns null)
  • ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found
Stack traces (one missing dir; repeated for each missing dir and each scan)
[ForkJoinPool.commonPool-worker-4] WARN org.reflections.Reflections - could not create Dir using com.thoughtworks.gauge.scan.ClasspathScanner$1@7a1867d5 from url file:/path/to/project/build/classes/java/main. skipping.
java.lang.NullPointerException: Cannot invoke "java.io.File.isDirectory()" because "file" is null
	at com.thoughtworks.gauge.scan.ClasspathScanner$1.createDir(ClasspathScanner.java:48)
	at org.reflections.vfs.Vfs.fromURL(Vfs.java:103)
	at org.reflections.vfs.Vfs.fromURL(Vfs.java:95)
	at org.reflections.Reflections.lambda$scan$2(Reflections.java:176)
	...
[ForkJoinPool.commonPool-worker-4] WARN org.reflections.Reflections - could not create Vfs.Dir from url. ignoring the exception and continuing
org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [file:/path/to/project/build/classes/java/main]
either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType.
	at org.reflections.vfs.Vfs.fromURL(Vfs.java:113)
	at org.reflections.vfs.Vfs.fromURL(Vfs.java:95)
	at org.reflections.Reflections.lambda$scan$2(Reflections.java:176)
	...

Steps are still discovered, so this is noise only, but it shows up on every run.

Changes

  • ClasspathHelper.getUrls(): skip classpath entries that don't exist (covers both ClasspathScanner and ParameterParsingChain)
  • ClasspathScanner: the custom UrlType no longer matches non-existent files
  • Add ClasspathHelperTest

Verification

Kotlin-only Gradle sample (org.gauge 3.0.0, Kotlin 2.1.21, slf4j-simple), ./gradlew gauge:

gauge-java NPE ReflectionsException Scanned URLs
master 10 10 35
this PR 0 0 30

Gradle puts source set output directories on the classpath even when they
were never created, e.g. build/classes/java/main in Kotlin-only projects.
These entries made Reflections log NullPointerException and
ReflectionsException stack traces for every scan.

Signed-off-by: Jun Sekine <jun@sakamo.to>
@jsoizo
jsoizo force-pushed the fix/skip-nonexistent-classpath-entries branch from 6ff9be5 to 7ff972d Compare October 9, 2026 07:53
@chadlwilson chadlwilson added the ReleaseCandidate If a PR is tagged with this label, after merging it will be released label Oct 11, 2026
@gaugebot

gaugebot Bot commented Oct 11, 2026

Copy link
Copy Markdown

@jsoizo Thank you for contributing to gauge-java. Your pull request has been labeled as a release candidate 🎉🎉.

Merging this PR will trigger a release.

Please bump up the version as part of this PR.

Instructions to bump the version can found at CONTRIBUTING.md

If the CONTRIBUTING.md file does not exist or does not include instructions about bumping up the version, please looks previous commits in git history to see what changes need to be done.

@chadlwilson chadlwilson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you could remove the unnecessarily noisy LLM comment and bump up the version, I think this is fine.

Copilot AI 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.

🟡 Changes recommended

Check converted files with exists() in both production paths.

2 open findings
What changed in this PR

This PR filters missing classpath entries to reduce Reflections scan warnings in Kotlin-only Gradle projects.

Changes:

  • Filters classpath URLs.
  • Restricts custom VFS URL handling.
  • Adds regression coverage for missing entries.

Review found that both existence checks only verify file conversion, so missing paths may still trigger warnings.

File Summary
src/​test/​java/​com/​thoughtworks/​gauge/​ClasspathHelperTest.java Tests missing classpath entry filtering.
src/​main/​java/​com/​thoughtworks/​gauge/​scan/​ClasspathScanner.java Updates custom URL matching.
src/​main/​java/​com/​thoughtworks/​gauge/​ClasspathHelper.java Filters classpath entries.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/main/java/com/thoughtworks/gauge/ClasspathHelper.java
Comment thread src/main/java/com/thoughtworks/gauge/scan/ClasspathScanner.java
Signed-off-by: Jun Sekine <jun@sakamo.to>
@jsoizo

jsoizo commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

@chadlwilson

Thank you for the feedback. I've removed the unnecessary comment.

and bump up the version,

I am not sure if I have understood your intention correctly, so please let me ask.
Was I supposed to make changes like this diff?

Details
diff --git a/java.json b/java.json
index 71df71a..1b10b2b 100644
--- a/java.json
+++ b/java.json
@@ -1,6 +1,6 @@
 {
   "id": "java",
-  "version": "1.0.3",
+  "version": "1.0.4",
   "description": "Java support for gauge",
   "install": {
     "windows": [],
diff --git a/pom.xml b/pom.xml
index 1b38dc4..f522ed0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
     <name>gauge-java</name>
     <groupId>com.thoughtworks.gauge</groupId>
     <artifactId>gauge-java</artifactId>
-    <version>1.0.3</version>
+    <version>1.0.4</version>
     <description>Java plugin for Gauge</description>
     <url>https://github.com/getgauge/gauge-java</url>
     <dependencyManagement>

@chadlwilson

Copy link
Copy Markdown
Contributor

Yes, like the bot comment alludes to 👍

Signed-off-by: Jun Sekine <jun@sakamo.to>
@jsoizo

jsoizo commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

@chadlwilson I've pushed a fix that bumps the version.

@chadlwilson

Copy link
Copy Markdown
Contributor

Could you look a the copilot comments and see if they have a point, or are nonsense?

@chadlwilson
chadlwilson merged commit 4366841 into getgauge:master Oct 17, 2026
23 checks passed
@jsoizo
jsoizo deleted the fix/skip-nonexistent-classpath-entries branch October 17, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ReleaseCandidate If a PR is tagged with this label, after merging it will be released

Development

Successfully merging this pull request may close these issues.

3 participants