mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8190733: Use Class::getPackageName in java.base implementation
Reviewed-by: mchung, rriggs
This commit is contained in:
parent
73f177ea06
commit
5d7c797278
5 changed files with 10 additions and 36 deletions
|
@ -495,8 +495,8 @@ public interface ObjectInputFilter {
|
|||
// Wildcard cases
|
||||
if (p.endsWith(".*")) {
|
||||
// Pattern is a package name with a wildcard
|
||||
final String pkg = p.substring(poffset, nameLen - 1);
|
||||
if (pkg.length() < 2) {
|
||||
final String pkg = p.substring(poffset, nameLen - 2);
|
||||
if (pkg.isEmpty()) {
|
||||
throw new IllegalArgumentException("package missing in: \"" + pattern + "\"");
|
||||
}
|
||||
if (negate) {
|
||||
|
@ -651,13 +651,12 @@ public interface ObjectInputFilter {
|
|||
* Returns {@code true} if the class is in the package.
|
||||
*
|
||||
* @param c a class
|
||||
* @param pkg a package name (including the trailing ".")
|
||||
* @param pkg a package name
|
||||
* @return {@code true} if the class is in the package,
|
||||
* otherwise {@code false}
|
||||
*/
|
||||
private static boolean matchesPackage(Class<?> c, String pkg) {
|
||||
String n = c.getName();
|
||||
return n.startsWith(pkg) && n.lastIndexOf('.') == pkg.length() - 1;
|
||||
return pkg.equals(c.getPackageName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1580,18 +1580,7 @@ public class ObjectStreamClass implements Serializable {
|
|||
*/
|
||||
private static boolean packageEquals(Class<?> cl1, Class<?> cl2) {
|
||||
return (cl1.getClassLoader() == cl2.getClassLoader() &&
|
||||
getPackageName(cl1).equals(getPackageName(cl2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns package name of given class.
|
||||
*/
|
||||
private static String getPackageName(Class<?> cl) {
|
||||
String s = cl.getName();
|
||||
int i = s.lastIndexOf('[');
|
||||
i = (i < 0) ? 0 : i + 2;
|
||||
int j = s.lastIndexOf('.');
|
||||
return (i < j) ? s.substring(i, j) : "";
|
||||
cl1.getPackageName().equals(cl2.getPackageName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue