JDK-8310267 : Javadoc for Class#isPrimitive() is incorrect regarding Class objects for primitives
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-06-18
  • Updated: 2024-10-17
  • Resolved: 2023-06-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 b04Fixed
Related Reports
Relates :  
Description
The Javadoc for java.lang.Class.isPrimitive() currently states:

> These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.

However, it is also possible to access each of the Class objects for primitives via boolean.class, byte.class, char.class, short.class, int.class, long.class, float.class, double.class, and void.class.

For example, the following unit test (using JUnit Jupiter and AssertJ) passes.

@Test
void isPrimitive() {
    assertThat(Integer.TYPE).isEqualTo(int.class);
    assertThat(Integer.TYPE).isSameAs(int.class);
    assertThat(Integer.TYPE.isPrimitive()).isTrue();
    assertThat(int.class.isPrimitive()).isTrue();
}

Please update the Javadoc for java.lang.Class.isPrimitive() to reflect that.

Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/14574 Date: 2023-06-21 00:00:54 +0000
17-10-2024

Changeset: 0314292c Author: Joe Darcy <darcy@openjdk.org> Date: 2023-06-23 19:35:57 +0000 URL: https://git.openjdk.org/jdk/commit/0314292cb2d55474d8fb3d0ef46129be7e4f1838
23-06-2023