Skip to content

Commit

Permalink
Class.getPackage() return null for array and primitve classes
Browse files Browse the repository at this point in the history
Per the javadoc:

public Package getPackage()
If this class represents an array type, a primitive type or void, this method
returns null.

Note that the reference implementation has this behaviour in Java 8, but it was
not a requirement until Java 9.

Also clean up javadoc format and comments.

Signed-off-by: Peter Bain <[email protected]>
  • Loading branch information
pdbain-ibm committed Oct 17, 2017
1 parent f50d159 commit 047cbca
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions jcl/src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -1784,9 +1784,10 @@ private static String getNonArrayClassPackageName(Class<?> clz) {
/**
* Answers the name of the package to which the receiver belongs.
* For example, Object.class.getPackageName() returns "java.lang".
* Returns null if this class represents an array type, a primitive type or void
* Returns "java.lang" if this class represents a primitive type or void,
* and the element type's package name in the case of an array type.
*
* @return the receiver's package name.
* @return String the receiver's package name
*
* @see #getPackage
*/
Expand Down Expand Up @@ -2159,14 +2160,17 @@ public String toGenericString() {

/**
* Returns the Package of which this class is a member.
* A class has a Package iff it was loaded from a SecureClassLoader
*
* @return Package the Package of which this class is a member or null
* A class has a Package iff it was loaded from a SecureClassLoader.
*
* @return Package the Package of which this class is a member
* or null in the case of primitive or array types
*/
public Package getPackage() {
if (isArray() || isPrimitive()) {
return null;
}
String packageName = getPackageName();
if (packageName == null) {
if (null == packageName) {
return null;
} else {
/*[IF Sidecar19-SE]*/
Expand Down

0 comments on commit 047cbca

Please sign in to comment.