[
https://issues.apache.org/jira/browse/LANG-1838?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Aryan Ganjoo updated LANG-1838:
-------------------------------
Description:
h3. Observed
For a class in the unnamed (default) package, the Class overloads of
{{ClassPathUtils.toFullyQualifiedName}} and {{toFullyQualifiedPath}} do not
produce a classpath-root resource name. On JDK 17, the package name is empty
and the methods return {{.Test.properties}} and {{/Test.properties}}. The
Package overloads also prepend a separator when given an empty-named package.
OpenJDK 8 source indicates that {{Class.getPackage()}} is null for an
unnamed-package class, so the original Class overloads pass null to a Package
overload and throw {{NullPointerException}}; that Java 8 path was not executed
locally.
h3. Expected
Both methods should return {{Test.properties}} for an unnamed-package context.
Named-package behavior should remain unchanged.
h3. Reproduction and validation
Place a class in the default package and call both overloads with
{{Test.properties}} as the resource name. On Commons Lang master
{{9c86ffe308e7c682df3b1cf76f27dfc5bb6a2243}}, the local JDK 17 regression
reproduced the leading separators. The corrected patch passed 21 focused tests
and 413 adjacent tests on JDK 17; its default Maven build completed
successfully. Java 8-target bytecode was compiled and OpenJDK 8 source was
inspected, but a Java 8 runtime test was not run locally. Other JDKs and
released binaries were not tested.
h3. Fix
Treat a null or empty package name as the classpath root without adding a
separator, preserving named-package and null-argument behavior. Implementation
PR: https://github.com/apache/commons-lang/pull/1824 . AI assistance was used
for discovery, implementation, tests, and review; the submitter reviewed the
exact revision.
was:
h3. Observed
For a class in the unnamed (default) package, the Class overloads of
{{ClassPathUtils.toFullyQualifiedName}} and {{toFullyQualifiedPath}} do not
produce a classpath-root resource name. On Java 8, {{Class.getPackage()}} is
null here and both calls throw {{NullPointerException}}. On Java 17, the
package name is empty and the methods return {{.Test.properties}} and
{{/Test.properties}} respectively. The Package overloads also prepend a
separator when given an empty-named package. A class loader can resolve
{{Test.properties}} at the classpath root, but not the leading-slash path
produced here.
h3. Expected
Both methods should return {{Test.properties}} for an unnamed-package context.
Named-package behavior should remain unchanged.
h3. Reproduction
Place a class in the default package and call both overloads with
{{Test.properties}} as the resource name. This reproduces on current Commons
Lang master {{9c86ffe308e7c682df3b1cf76f27dfc5bb6a2243}}. A local regression
failed on the unmodified Java 8 source (two NPE errors); the corrected
candidate passed 21 focused tests on Java 8 and Java 17. The Java 8 default
Maven build also passed. Java 11/21/25 and released binaries were not tested.
h3. Scope and possible fix
Treat a null or empty package name as the classpath root without adding a
separator; preserve named-package behavior. This is a local candidate only, not
a submitted PR. AI assistance was used for discovery, test and patch
preparation, and local validation.
> ClassPathUtils mishandles resources in the unnamed package
> ----------------------------------------------------------
>
> Key: LANG-1838
> URL: https://issues.apache.org/jira/browse/LANG-1838
> Project: Commons Lang
> Issue Type: Bug
> Reporter: Aryan Ganjoo
> Priority: Minor
>
> h3. Observed
> For a class in the unnamed (default) package, the Class overloads of
> {{ClassPathUtils.toFullyQualifiedName}} and {{toFullyQualifiedPath}} do not
> produce a classpath-root resource name. On JDK 17, the package name is empty
> and the methods return {{.Test.properties}} and {{/Test.properties}}. The
> Package overloads also prepend a separator when given an empty-named package.
> OpenJDK 8 source indicates that {{Class.getPackage()}} is null for an
> unnamed-package class, so the original Class overloads pass null to a Package
> overload and throw {{NullPointerException}}; that Java 8 path was not
> executed locally.
> h3. Expected
> Both methods should return {{Test.properties}} for an unnamed-package
> context. Named-package behavior should remain unchanged.
> h3. Reproduction and validation
> Place a class in the default package and call both overloads with
> {{Test.properties}} as the resource name. On Commons Lang master
> {{9c86ffe308e7c682df3b1cf76f27dfc5bb6a2243}}, the local JDK 17 regression
> reproduced the leading separators. The corrected patch passed 21 focused
> tests and 413 adjacent tests on JDK 17; its default Maven build completed
> successfully. Java 8-target bytecode was compiled and OpenJDK 8 source was
> inspected, but a Java 8 runtime test was not run locally. Other JDKs and
> released binaries were not tested.
> h3. Fix
> Treat a null or empty package name as the classpath root without adding a
> separator, preserving named-package and null-argument behavior.
> Implementation PR: https://github.com/apache/commons-lang/pull/1824 . AI
> assistance was used for discovery, implementation, tests, and review; the
> submitter reviewed the exact revision.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)