Skip to content

fix(properties): the class loader fallback of loadProperties(Class, ...) asks the given class (#38) - #54

Merged
astrapi69 merged 2 commits into
developfrom
fix/38-class-loader-fallback
Nov 7, 2026
Merged

astrapi69 merged 2 commits into
developfrom
fix/38-class-loader-fallback

Conversation

@astrapi69

Copy link
Copy Markdown
Owner

Closes #38

PropertiesFileExtensions.loadProperties(Class, String) fell back to ClassExtensions.getResourceAsStream(clazz.getClass(), name). clazz.getClass() is always java.lang.Class, so the fallback asked the boot loader and then the class loader of the first attempt again, never the loader of the given class; the three-argument overload has the same behaviour. Found while moving lightblueseas/email-tails to 6.1.

What changes

  1. test(properties): pin that the class loader fallback of loadProperties(Class, ...) finds nothing (#38) (af7febe)
    • PropertiesFileExtensionsClassLoaderTest builds a class loader of its own over a temporary directory (parent: the platform class loader), loads the new test helper ClassLoaderMarker through it once more and writes the properties file next to it, where the class loader of the tests does not see it (the setup asserts both). For three ways to name the file (file name relative to the package of the class, absolute path with a leading slash, package path and file name of the three-argument overload) it pins today's result: null.
  2. fix(properties): the class loader fallback of loadProperties(Class, ...) asks the given class (#38) (a56902b)
    • ClassExtensions.getResourceAsStream(clazz, name), as the issue expects: the name resolves as Class.getResourceAsStream does; the fallback's stream is closed (try-with-resources)
    • the Javadoc of both overloads says which loader is asked when, how the name resolves in the fallback, and that null comes back if neither finds the file (as the code did before)
    • the three rows turn: each loads the file and reads found=next to the class

Evidence

JDK 17.0.20 (Temurin; the workflow sets up '17', projectSourceCompatibility=17), ./gradlew spotlessApply build --console=plain through the build-slot script; counts summed over build/test-results/test/TEST-*.xml:

commit result files tests failures errors skipped
before 869e0db (develop) 28 157 0 0 0
pinning test af7febe 29 160 0 0 0
fix a56902b 29 160 0 0 0

The pinning test on af7febe is the counter-run of the fix: the same three rows against the old code give null.

…s(Class, ...) finds nothing (#38)

PropertiesFileExtensions.loadProperties(Class, String) falls back to
ClassExtensions.getResourceAsStream(clazz.getClass(), name) when the class
loader of the current thread does not find the file. clazz.getClass() is
always java.lang.Class, so the fallback asks the boot loader and then the
same loader as the first attempt again, never the loader of the given class.

The test builds a class loader of its own over a temporary directory, with
the platform class loader as its parent, loads ClassLoaderMarker through it
once more and puts the properties file next to it, where the class loader
of the tests does not see it. For the three ways to name the file (the file
name relative to the package of the class, the absolute path with a leading
slash, the package path and the file name of the three-argument overload)
it pins today's result, null. The fix turns these rows.
…..) asks the given class (#38)

loadProperties(Class, String) passed clazz.getClass(), which is always
java.lang.Class, to the fallback, so the caller's class loader was never
asked; it went unnoticed because the first attempt, the class loader of the
current thread, usually finds the file. Found while moving
lightblueseas/email-tails to 6.1, whose SendEmail loads its default
mail.properties this way.

The fallback now passes the given class, as the issue expects, so the name
resolves as Class.getResourceAsStream does: relative to the package of the
class, or from the root of its class loader with a leading slash. The
stream of the fallback is closed after loading. The Javadoc of both
overloads says which loader is asked when and that null comes back if
neither finds the file, which the code did before as well.

Closes #38
@codecov

codecov Bot commented Nov 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 74.84%. Comparing base (869e0db) to head (a56902b).

Files with missing lines Patch % Lines
...rcebundle/properties/PropertiesFileExtensions.java 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop      #54      +/-   ##
=============================================
+ Coverage      74.36%   74.84%   +0.48%     
- Complexity       204      205       +1     
=============================================
  Files             25       25              
  Lines            831      831              
  Branches         140      140              
=============================================
+ Hits             618      622       +4     
+ Misses           134      130       -4     
  Partials          79       79              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@astrapi69
astrapi69 merged commit 0109bcb into develop Nov 7, 2026
9 checks passed
@astrapi69
astrapi69 deleted the fix/38-class-loader-fallback branch November 7, 2026 08:51
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.

PropertiesFileExtensions.loadProperties(Class, String) passes clazz.getClass() instead of clazz to the class loader fallback

1 participant