RFR: 8343437: ClassDesc.of incorrectly permitting empty names
Chen Liang
liach at openjdk.org
Fri Nov 1 17:31:28 UTC 2024
On Fri, 1 Nov 2024 13:58:01 GMT, Chen Liang <liach at openjdk.org> wrote:
> An oversight in the patch for [JDK-8338544](https://bugs.openjdk.org/browse/JDK-8338544) #20665 caused `ClassDesc` to incorrectly accept empty strings as binary names, so erroneous calls `ClassDesc.of("")` and `ClassDesc.ofInternalName("")` return instead of throw IllegalArgumentExceptions. This patch fixes that problem by updating the package separator tracking in `validateBinary/InternalClassName` to closely resemble that in `skipOverFieldSignature` to prohibit empty strings, leading, trailing, or consecutive separator chars.
>
> In addition, the package name validation erroneously does not prohibit leading, trailing or consecutive separator chars. (Package names are derived from class or interface names, so the same restrictions shall apply) Make package name validation reuse class or interface name validation and added those cases to the test suite.
Before 8338544, the binary/internal name validation was partial. It missed a few validations performed by `skipOverFieldSignature`: no empty strings, leading or trailing or consecutive separator chars. In 8338544, the empty string validation was incorrectly missed.
PackageDesc in theory should not accept leading or trailing or consecutive separator chars, just like the names of classes and interfaces do not. Added validations for PackageDesc, so if we wish to create ClassDesc from a PackageDesc, we won't find invalid packages that cannot have classes or interfaces.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21830#issuecomment-2452283588
More information about the core-libs-dev
mailing list