src/java.base/share/classes/java/io/ObjectInputFilter.java
changeset 47722 ce6ff74192fc
parent 47216 71c04702a3d5
child 49438 879cf9f18688
equal deleted inserted replaced
47721:d2b306a70bf1 47722:ce6ff74192fc
   493                     final Function<Class<?>, Status> patternFilter;
   493                     final Function<Class<?>, Status> patternFilter;
   494                     if (p.endsWith("*")) {
   494                     if (p.endsWith("*")) {
   495                         // Wildcard cases
   495                         // Wildcard cases
   496                         if (p.endsWith(".*")) {
   496                         if (p.endsWith(".*")) {
   497                             // Pattern is a package name with a wildcard
   497                             // Pattern is a package name with a wildcard
   498                             final String pkg = p.substring(poffset, nameLen - 1);
   498                             final String pkg = p.substring(poffset, nameLen - 2);
   499                             if (pkg.length() < 2) {
   499                             if (pkg.isEmpty()) {
   500                                 throw new IllegalArgumentException("package missing in: \"" + pattern + "\"");
   500                                 throw new IllegalArgumentException("package missing in: \"" + pattern + "\"");
   501                             }
   501                             }
   502                             if (negate) {
   502                             if (negate) {
   503                                 // A Function that fails if the class starts with the pattern, otherwise don't care
   503                                 // A Function that fails if the class starts with the pattern, otherwise don't care
   504                                 patternFilter = c -> matchesPackage(c, pkg) ? Status.REJECTED : Status.UNDECIDED;
   504                                 patternFilter = c -> matchesPackage(c, pkg) ? Status.REJECTED : Status.UNDECIDED;
   649 
   649 
   650             /**
   650             /**
   651              * Returns {@code true} if the class is in the package.
   651              * Returns {@code true} if the class is in the package.
   652              *
   652              *
   653              * @param c   a class
   653              * @param c   a class
   654              * @param pkg a package name (including the trailing ".")
   654              * @param pkg a package name
   655              * @return {@code true} if the class is in the package,
   655              * @return {@code true} if the class is in the package,
   656              * otherwise {@code false}
   656              * otherwise {@code false}
   657              */
   657              */
   658             private static boolean matchesPackage(Class<?> c, String pkg) {
   658             private static boolean matchesPackage(Class<?> c, String pkg) {
   659                 String n = c.getName();
   659                 return pkg.equals(c.getPackageName());
   660                 return n.startsWith(pkg) && n.lastIndexOf('.') == pkg.length() - 1;
       
   661             }
   660             }
   662 
   661 
   663             /**
   662             /**
   664              * Returns the pattern used to create this filter.
   663              * Returns the pattern used to create this filter.
   665              * @return the pattern used to create this filter
   664              * @return the pattern used to create this filter