Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add primitive classes to package java.lang #905

Merged

Conversation

codecholeric
Copy link
Collaborator

So far primitive types like int have been in the default package "", since their Package object from the Reflection API is null and that seemed like the best matching ArchUnit version (since ArchUnit does not use null within the public API and the choice would then just have been to make the JavaPackage Optional just because of a couple of corner cases). Starting with Java 9 the Reflection API introduced a new method Class.getPackageName() though, which would return java.lang for primitives and the package of the component type for arrays. Luckily for arrays ArchUnit is already consistent, because we decided long ago that this behavior for the package name would make sense. This commit now makes the package of primitives again consistent with the Reflection API by putting primitive types into the package java.lang.

This is a breaking change in the sense that users who have ignored the default package "" for their rules to exclude primitives will now potentially see them again (except if they also excluded java.lang).

After migrating to Java 8 there are now quite some places where type information can actually be inferred instead of having to be specified explicitly.

Signed-off-by: Peter Gafert <[email protected]>
So far primitive types like `int` have been in the default package `""`, since their `Package` object from the Reflection API is `null` and that seemed like the best matching ArchUnit version (since ArchUnit does not use `null` within the public API and the choice would then just have been to make the `JavaPackage` `Optional` just because of a couple of corner cases). Starting with Java 9 the Reflection API introduced a new method `Class.getPackageName()` though, which would return `java.lang` for primitives and the package of the component type for arrays. Luckily for arrays ArchUnit is already consistent, because we decided long ago that this behavior for the package name would make sense. This commit now makes the package of primitives again consistent with the Reflection API by putting primitive types into the package `java.lang`.

Signed-off-by: Peter Gafert <[email protected]>
@codecholeric codecholeric added this to the 1.0.0 milestone Jul 8, 2022
@codecholeric codecholeric merged commit 2e3994d into main Jul 8, 2022
@codecholeric codecholeric deleted the make-primitive-packages-consistent-with-Reflection-API branch July 8, 2022 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant