Skip to content

[LANG-1838] Fix resource paths for unnamed packages - #1824

Merged
garydgregory merged 1 commit into
apache:masterfrom
AryanRG:LANG-1838-default-package-resources
Oct 17, 2026
Merged

garydgregory merged 1 commit into
apache:masterfrom
AryanRG:LANG-1838-default-package-resources

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix ClassPathUtils resource-name and path construction for classes and Package objects in the unnamed package. The existing methods added a leading . or / (and a Java 8 unnamed-package class could have a null getPackage() result). The corrected methods return the resource name unchanged for an unnamed package while preserving named-package and null-argument behavior.

Jira: LANG-1838

Verification

  • Added an unnamed-package test fixture and regressions for both Class<?> and Package overloads; existing named-package, primitive/array and null cases remain covered.
  • ClassPathUtilsTest, ClassLoaderUtilsTest, and ClassUtilsTest: 413 tests passed on JDK 17; Checkstyle passed.
  • Default Maven build: completed successfully on JDK 17.
  • Java 8-target bytecode was compiled and Java 8 source behavior checked; a Java 8 runtime and hosted CI were not run locally.

Contributor checklist

  • Read the contribution guidelines.
  • Read the ASF Generative Tooling Guidance.
  • AI assistance was used. OpenAI Codex helped investigate, implement, test, and review this patch; the submitter reviewed the exact revision before submission.
  • Ran the default Maven build successfully.
  • Added regression tests for the behavior change.
  • Described the issue and correction above.
  • Used a Jira-keyed commit subject and descriptive body.

Return the unprefixed resource name for an empty Package name, and handle Java 8 unnamed-package classes whose getPackage() is null. Add focused regressions for class and Package overloads while retaining named-package and null behavior.

AI-Assisted-by: OpenAI Codex

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

🟢 Approval recommended

The localized changes preserve existing behavior outside unnamed packages, with regression coverage and no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes ClassPathUtils resource construction for unnamed packages while preserving named-package and null-argument behavior.

Changes:

  • Avoids leading separators for unnamed packages.
  • Handles Java 8 unnamed-package classes with a null package.
  • Adds regression tests and an unnamed-package fixture.
File Description
src/​test/​java/​org/​apache/​commons/​lang3/​ClassPathUtilsTest.java Tests unnamed packages and primitive/array behavior.
src/​test/​java/​ClassPathUtilsDefaultPackage.java Adds an unnamed-package fixture.
src/​main/​java/​org/​apache/​commons/​lang3/​ClassPathUtils.java Corrects resource-name and path construction.

Review effort: Balanced

@garydgregory
garydgregory merged commit e985f2e into apache:master Oct 17, 2026
22 of 23 checks passed
@garydgregory

Copy link
Copy Markdown
Member

@AryanRG PR merged 🚀 , thank you. Note that the tests were incomplete. See the subsequent commit af4b2a2.

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.

3 participants