# HG changeset patch # User alanb # Date 1387095101 0 # Node ID b7163958d6d99f68390739e76ec9ede199620254 # Parent 8dc8af2df113d6e10d52421072d6738b43b149a6 8029805: Remove LogManager addPropertyChangeListener and removePropertyChangeListener methods 8029806: Remove Packer/Unpacker addPropertyChangeLister and removePropertyListener methods Reviewed-by: dfuchs, tbell, mchung, ihse diff -r 8dc8af2df113 -r b7163958d6d9 jdk/make/CreateJars.gmk --- a/jdk/make/CreateJars.gmk Sat Dec 14 20:36:10 2013 -0800 +++ b/jdk/make/CreateJars.gmk Sun Dec 15 08:11:41 2013 +0000 @@ -298,29 +298,6 @@ @$(JAVAC) -d $(@D)/../../ $(@D)/$(VERSION_JAVA_FILE) -# Support for removing the addPropertyChangeListener and removePropertyChangeListener -# methods from classes that only go into the profile builds. -BEANLESS_CLASSES = $(IMAGES_OUTPUTDIR)/beanless - -# When there are $ characters in filenames we have some very subtle interactions between -# make expansion and shell expansion. In this particular case $< will contain a single $ while -# $@ will contain \$. So we have to pass $< in single-quotes to avoid shell expansion -$(BEANLESS_CLASSES)/%: $(JDK_OUTPUTDIR)/classes/% - $(MKDIR) -p $(@D) - $(TOOL_REMOVEMETHODS) '$<' $@ addPropertyChangeListener removePropertyChangeListener - -CLASSES_TO_DEBEAN = \ - java/util/logging/LogManager.class \ - java/util/jar/Pack200\$$Packer.class \ - java/util/jar/Pack200\$$Unpacker.class \ - com/sun/java/util/jar/pack/PackerImpl.class \ - com/sun/java/util/jar/pack/UnpackerImpl.class - -ifneq ($(PROFILE), ) - BEANLESS_CLASSES_TARGETS := $(addprefix $(BEANLESS_CLASSES)/, $(CLASSES_TO_DEBEAN)) -endif - - RT_JAR_CREATE_OPTIONS := c0fm RT_JAR_UPDATE_OPTIONS := u0f ifeq ($(COMPRESS_JARS), true) @@ -333,7 +310,7 @@ $(IMAGES_OUTPUTDIR)/lib$(PROFILE)/rt.jar: \ CLASS_FILE = $(if $(PROFILE), $(strip $(foreach class, $(PROFILE_VERSION_CLASS_TARGETS), $(if $(findstring $(PROFILE), $(class)), $(class)))), NO_SUCH_FILE) # This is the real target -$(IMAGES_OUTPUTDIR)/lib$(PROFILE)/rt.jar: $(IMAGES_OUTPUTDIR)/lib$(PROFILE)/_the.rt.jar.contents $(RT_JAR_MANIFEST_FILE) $(PROFILE_VERSION_CLASS_TARGETS) $(BEANLESS_CLASSES_TARGETS) +$(IMAGES_OUTPUTDIR)/lib$(PROFILE)/rt.jar: $(IMAGES_OUTPUTDIR)/lib$(PROFILE)/_the.rt.jar.contents $(RT_JAR_MANIFEST_FILE) $(PROFILE_VERSION_CLASS_TARGETS) $(ECHO) Creating rt.jar $(PROFILE) Compressed=$(COMPRESS_JARS) $(MKDIR) -p $(@D) $(RM) $@ $@.tmp @@ -344,8 +321,6 @@ $(ECHO) Updating rt.jar $(PROFILE) && \ $(CD) $(patsubst %$(VERSION_CLASS_PATH), %, $(CLASS_FILE)) && \ $(JAR) $(RT_JAR_UPDATE_OPTIONS) $@.tmp $(VERSION_CLASS_PATH); \ - $(CD) $(BEANLESS_CLASSES) && \ - $(JAR) $(RT_JAR_UPDATE_OPTIONS) $@.tmp $(CLASSES_TO_DEBEAN); \ fi $(MV) $@.tmp $@ diff -r 8dc8af2df113 -r b7163958d6d9 jdk/make/Tools.gmk --- a/jdk/make/Tools.gmk Sat Dec 14 20:36:10 2013 -0800 +++ b/jdk/make/Tools.gmk Sun Dec 15 08:11:41 2013 +0000 @@ -122,10 +122,6 @@ TOOL_CLDRCONVERTER = $(JAVA) -cp $(JDK_OUTPUTDIR)/btclasses \ build.tools.cldrconverter.CLDRConverter -TOOL_REMOVEMETHODS = $(JAVA) -Xbootclasspath/p:$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar \ - -cp $(JDK_OUTPUTDIR)/btclasses:$(JDK_OUTPUTDIR) \ - build.tools.classfile.RemoveMethods - TOOL_CHECKDEPS = $(JAVA) -Xbootclasspath/p:$(LANGTOOLS_OUTPUTDIR)/dist/bootstrap/lib/javac.jar \ -cp $(JDK_OUTPUTDIR)/btclasses:$(JDK_OUTPUTDIR) \ build.tools.deps.CheckDeps diff -r 8dc8af2df113 -r b7163958d6d9 jdk/make/src/classes/build/tools/classfile/RemoveMethods.java --- a/jdk/make/src/classes/build/tools/classfile/RemoveMethods.java Sat Dec 14 20:36:10 2013 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package build.tools.classfile; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Set; -import java.util.HashSet; - -import com.sun.tools.classfile.AccessFlags; -import com.sun.tools.classfile.Attributes; -import com.sun.tools.classfile.ClassFile; -import com.sun.tools.classfile.ClassWriter; -import com.sun.tools.classfile.ConstantPool; -import com.sun.tools.classfile.Field; -import com.sun.tools.classfile.Method; - -public class RemoveMethods { - - public static void main(String[] args) throws Exception { - if (args.length < 2) { - System.err.println("Usage: java RemoveMethods classfile output [method...]"); - System.exit(-1); - } - - // class file to read - Path input = Paths.get(args[0]); - - // class file to write, if directory then use the name of the input - Path output = Paths.get(args[1]); - if (Files.isDirectory(output)) - output = output.resolve(input.getFileName()); - - // the methods to remove - Set methodsToRemove = new HashSet<>(); - int i = 2; - while (i < args.length) - methodsToRemove.add(args[i++]); - - // read class file - ClassFile cf; - try (InputStream in = Files.newInputStream(input)) { - cf = ClassFile.read(in); - } - - final int magic = cf.magic; - final int major_version = cf.major_version; - final int minor_version = cf.minor_version; - final ConstantPool cp = cf.constant_pool; - final AccessFlags access_flags = cf.access_flags; - final int this_class = cf.this_class; - final int super_class = cf.super_class; - final int[] interfaces = cf.interfaces; - final Field[] fields = cf.fields; - final Attributes class_attrs = cf.attributes; - - // remove the requested methods, no signature check at this time - Method[] methods = cf.methods; - i = 0; - while (i < methods.length) { - Method m = methods[i]; - String name = m.getName(cp); - if (methodsToRemove.contains(name)) { - int len = methods.length; - Method[] newMethods = new Method[len-1]; - if (i > 0) - System.arraycopy(methods, 0, newMethods, 0, i); - int after = methods.length - i - 1; - if (after > 0) - System.arraycopy(methods, i+1, newMethods, i, after); - methods = newMethods; - String paramTypes = m.descriptor.getParameterTypes(cp); - System.out.format("Removed method %s%s from %s%n", - name, paramTypes, cf.getName()); - continue; - } - i++; - } - - // TBD, prune constant pool of entries that are no longer referenced - - // re-write class file - cf = new ClassFile(magic, minor_version, major_version, cp, access_flags, - this_class, super_class, interfaces, fields, methods, class_attrs); - try (OutputStream out = Files.newOutputStream(output)) { - new ClassWriter().write(cf, out); - } - } -} diff -r 8dc8af2df113 -r b7163958d6d9 jdk/src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java --- a/jdk/src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java Sat Dec 14 20:36:10 2013 -0800 +++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/PackerImpl.java Sun Dec 15 08:11:41 2013 +0000 @@ -26,7 +26,6 @@ package com.sun.java.util.jar.pack; import com.sun.java.util.jar.pack.Attribute.Layout; -import java.beans.PropertyChangeListener; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -136,23 +135,6 @@ in.close(); } } - /** - * Register a listener for changes to options. - * @param listener An object to be invoked when a property is changed. - */ - public void addPropertyChangeListener(PropertyChangeListener listener) { - props.addListener(listener); - } - - /** - * Remove a listener for the PropertyChange event. - * @param listener The PropertyChange listener to be removed. - */ - public void removePropertyChangeListener(PropertyChangeListener listener) { - props.removeListener(listener); - } - - // All the worker bees..... // The packer worker. diff -r 8dc8af2df113 -r b7163958d6d9 jdk/src/share/classes/com/sun/java/util/jar/pack/PropMap.java --- a/jdk/src/share/classes/com/sun/java/util/jar/pack/PropMap.java Sat Dec 14 20:36:10 2013 -0800 +++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/PropMap.java Sun Dec 15 08:11:41 2013 +0000 @@ -40,9 +40,6 @@ import java.util.SortedMap; import java.util.TreeMap; import java.util.jar.Pack200; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; /** * Control block for publishing Pack200 options to the other classes. @@ -51,30 +48,9 @@ final class PropMap implements SortedMap { private final TreeMap theMap = new TreeMap<>();; - // type is erased, elements are of type java.beans.PropertyChangeListener - private final List listenerList = new ArrayList<>(1); - - void addListener(Object listener) { - assert Beans.isPropertyChangeListener(listener); - listenerList.add(listener); - } - - void removeListener(Object listener) { - assert Beans.isPropertyChangeListener(listener); - listenerList.remove(listener); - } - // Override: public String put(String key, String value) { String oldValue = theMap.put(key, value); - if (value != oldValue && !listenerList.isEmpty()) { - assert Beans.isBeansPresent(); - // Post the property change event. - Object event = Beans.newPropertyChangeEvent(this, key, oldValue, value); - for (Object listener : listenerList) { - Beans.invokePropertyChange(listener, event); - } - } return oldValue; } @@ -341,113 +317,4 @@ public String lastKey() { return theMap.lastKey(); } - - /** - * A class that provides access to the java.beans.PropertyChangeListener - * and java.beans.PropertyChangeEvent without creating a static dependency - * on java.beans. This class can be removed once the addPropertyChangeListener - * and removePropertyChangeListener methods are removed from Packer and - * Unpacker. - */ - private static class Beans { - private static final Class propertyChangeListenerClass = - getClass("java.beans.PropertyChangeListener"); - - private static final Class propertyChangeEventClass = - getClass("java.beans.PropertyChangeEvent"); - - private static final Method propertyChangeMethod = - getMethod(propertyChangeListenerClass, - "propertyChange", - propertyChangeEventClass); - - private static final Constructor propertyEventCtor = - getConstructor(propertyChangeEventClass, - Object.class, - String.class, - Object.class, - Object.class); - - private static Class getClass(String name) { - try { - return Class.forName(name, true, Beans.class.getClassLoader()); - } catch (ClassNotFoundException e) { - return null; - } - } - private static Constructor getConstructor(Class c, Class... types) { - try { - return (c == null) ? null : c.getDeclaredConstructor(types); - } catch (NoSuchMethodException x) { - throw new AssertionError(x); - } - } - - private static Method getMethod(Class c, String name, Class... types) { - try { - return (c == null) ? null : c.getMethod(name, types); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } - } - - /** - * Returns {@code true} if java.beans is present. - */ - static boolean isBeansPresent() { - return propertyChangeListenerClass != null && - propertyChangeEventClass != null; - } - - /** - * Returns {@code true} if the given object is a PropertyChangeListener - */ - static boolean isPropertyChangeListener(Object obj) { - if (propertyChangeListenerClass == null) { - return false; - } else { - return propertyChangeListenerClass.isInstance(obj); - } - } - - /** - * Returns a new PropertyChangeEvent with the given source, property - * name, old and new values. - */ - static Object newPropertyChangeEvent(Object source, String prop, - Object oldValue, Object newValue) - { - try { - return propertyEventCtor.newInstance(source, prop, oldValue, newValue); - } catch (InstantiationException | IllegalAccessException x) { - throw new AssertionError(x); - } catch (InvocationTargetException x) { - Throwable cause = x.getCause(); - if (cause instanceof Error) - throw (Error)cause; - if (cause instanceof RuntimeException) - throw (RuntimeException)cause; - throw new AssertionError(x); - } - } - - /** - * Invokes the given PropertyChangeListener's propertyChange method - * with the given event. - */ - static void invokePropertyChange(Object listener, Object ev) { - try { - propertyChangeMethod.invoke(listener, ev); - } catch (IllegalAccessException x) { - throw new AssertionError(x); - } catch (InvocationTargetException x) { - Throwable cause = x.getCause(); - if (cause instanceof Error) - throw (Error)cause; - if (cause instanceof RuntimeException) - throw (RuntimeException)cause; - throw new AssertionError(x); - } - } - } } diff -r 8dc8af2df113 -r b7163958d6d9 jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java --- a/jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java Sat Dec 14 20:36:10 2013 -0800 +++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/UnpackerImpl.java Sun Dec 15 08:11:41 2013 +0000 @@ -25,7 +25,6 @@ package com.sun.java.util.jar.pack; -import java.beans.PropertyChangeListener; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -55,24 +54,6 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker { - - /** - * Register a listener for changes to options. - * @param listener An object to be invoked when a property is changed. - */ - public void addPropertyChangeListener(PropertyChangeListener listener) { - props.addListener(listener); - } - - - /** - * Remove a listener for the PropertyChange event. - * @param listener The PropertyChange listener to be removed. - */ - public void removePropertyChangeListener(PropertyChangeListener listener) { - props.removeListener(listener); - } - public UnpackerImpl() {} diff -r 8dc8af2df113 -r b7163958d6d9 jdk/src/share/classes/java/util/jar/Pack200.java --- a/jdk/src/share/classes/java/util/jar/Pack200.java Sat Dec 14 20:36:10 2013 -0800 +++ b/jdk/src/share/classes/java/util/jar/Pack200.java Sun Dec 15 08:11:41 2013 +0000 @@ -29,9 +29,6 @@ import java.io.OutputStream; import java.io.File; import java.io.IOException; -import java.beans.PropertyChangeListener; - - /** @@ -571,54 +568,6 @@ * @exception IOException if an error is encountered. */ void pack(JarInputStream in, OutputStream out) throws IOException ; - - /** - * Registers a listener for PropertyChange events on the properties map. - * This is typically used by applications to update a progress bar. - * - *

The default implementation of this method does nothing and has - * no side-effects.

- * - *

WARNING: This method is omitted from the interface - * declaration in all subset Profiles of Java SE that do not include - * the {@code java.beans} package.

- - * @see #properties - * @see #PROGRESS - * @param listener An object to be invoked when a property is changed. - * @deprecated The dependency on {@code PropertyChangeListener} creates - * a significant impediment to future modularization of the - * Java platform. This method will be removed in a future - * release. - * Applications that need to monitor progress of the packer - * can poll the value of the {@link #PROGRESS PROGRESS} - * property instead. - */ - @Deprecated - default void addPropertyChangeListener(PropertyChangeListener listener) { - } - - /** - * Remove a listener for PropertyChange events, added by - * the {@link #addPropertyChangeListener}. - * - *

The default implementation of this method does nothing and has - * no side-effects.

- * - *

WARNING: This method is omitted from the interface - * declaration in all subset Profiles of Java SE that do not include - * the {@code java.beans} package.

- * - * @see #addPropertyChangeListener - * @param listener The PropertyChange listener to be removed. - * @deprecated The dependency on {@code PropertyChangeListener} creates - * a significant impediment to future modularization of the - * Java platform. This method will be removed in a future - * release. - */ - @Deprecated - default void removePropertyChangeListener(PropertyChangeListener listener) { - } } /** @@ -730,54 +679,6 @@ * @exception IOException if an error is encountered. */ void unpack(File in, JarOutputStream out) throws IOException; - - /** - * Registers a listener for PropertyChange events on the properties map. - * This is typically used by applications to update a progress bar. - * - *

The default implementation of this method does nothing and has - * no side-effects.

- * - *

WARNING: This method is omitted from the interface - * declaration in all subset Profiles of Java SE that do not include - * the {@code java.beans} package.

- * - * @see #properties - * @see #PROGRESS - * @param listener An object to be invoked when a property is changed. - * @deprecated The dependency on {@code PropertyChangeListener} creates - * a significant impediment to future modularization of the - * Java platform. This method will be removed in a future - * release. - * Applications that need to monitor progress of the - * unpacker can poll the value of the {@link #PROGRESS - * PROGRESS} property instead. - */ - @Deprecated - default void addPropertyChangeListener(PropertyChangeListener listener) { - } - - /** - * Remove a listener for PropertyChange events, added by - * the {@link #addPropertyChangeListener}. - * - *

The default implementation of this method does nothing and has - * no side-effects.

- * - *

WARNING: This method is omitted from the interface - * declaration in all subset Profiles of Java SE that do not include - * the {@code java.beans} package.

- * - * @see #addPropertyChangeListener - * @param listener The PropertyChange listener to be removed. - * @deprecated The dependency on {@code PropertyChangeListener} creates - * a significant impediment to future modularization of the - * Java platform. This method will be removed in a future - * release. - */ - @Deprecated - default void removePropertyChangeListener(PropertyChangeListener listener) { - } } // Private stuff.... diff -r 8dc8af2df113 -r b7163958d6d9 jdk/src/share/classes/java/util/logging/LogManager.java --- a/jdk/src/share/classes/java/util/logging/LogManager.java Sat Dec 14 20:36:10 2013 -0800 +++ b/jdk/src/share/classes/java/util/logging/LogManager.java Sun Dec 15 08:11:41 2013 +0000 @@ -31,10 +31,6 @@ import java.security.*; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.beans.PropertyChangeListener; import sun.misc.JavaAWTAccess; import sun.misc.SharedSecrets; @@ -156,10 +152,6 @@ private volatile Properties props = new Properties(); private final static Level defaultLevel = Level.INFO; - // The map of the registered listeners. The map value is the registration - // count to allow for cases where the same listener is registered many times. - private final Map listenerMap = new HashMap<>(); - // LoggerContext for system loggers and user loggers private final LoggerContext systemContext = new SystemLoggerContext(); private final LoggerContext userContext = new LoggerContext(); @@ -390,85 +382,6 @@ } } - /** - * Adds an event listener to be invoked when the logging - * properties are re-read. Adding multiple instances of - * the same event Listener results in multiple entries - * in the property event listener table. - * - *

WARNING: This method is omitted from this class in all subset - * Profiles of Java SE that do not include the {@code java.beans} package. - *

- * - * @param l event listener - * @exception SecurityException if a security manager exists and if - * the caller does not have LoggingPermission("control"). - * @exception NullPointerException if the PropertyChangeListener is null. - * @deprecated The dependency on {@code PropertyChangeListener} creates a - * significant impediment to future modularization of the Java - * platform. This method will be removed in a future release. - * The global {@code LogManager} can detect changes to the - * logging configuration by overridding the {@link - * #readConfiguration readConfiguration} method. - */ - @Deprecated - public void addPropertyChangeListener(PropertyChangeListener l) throws SecurityException { - PropertyChangeListener listener = Objects.requireNonNull(l); - checkPermission(); - synchronized (listenerMap) { - // increment the registration count if already registered - Integer value = listenerMap.get(listener); - value = (value == null) ? 1 : (value + 1); - listenerMap.put(listener, value); - } - } - - /** - * Removes an event listener for property change events. - * If the same listener instance has been added to the listener table - * through multiple invocations of addPropertyChangeListener, - * then an equivalent number of - * removePropertyChangeListener invocations are required to remove - * all instances of that listener from the listener table. - *

- * Returns silently if the given listener is not found. - * - *

WARNING: This method is omitted from this class in all subset - * Profiles of Java SE that do not include the {@code java.beans} package. - *

- * - * @param l event listener (can be null) - * @exception SecurityException if a security manager exists and if - * the caller does not have LoggingPermission("control"). - * @deprecated The dependency on {@code PropertyChangeListener} creates a - * significant impediment to future modularization of the Java - * platform. This method will be removed in a future release. - * The global {@code LogManager} can detect changes to the - * logging configuration by overridding the {@link - * #readConfiguration readConfiguration} method. - */ - @Deprecated - public void removePropertyChangeListener(PropertyChangeListener l) throws SecurityException { - checkPermission(); - if (l != null) { - PropertyChangeListener listener = l; - synchronized (listenerMap) { - Integer value = listenerMap.get(listener); - if (value != null) { - // remove from map if registration count is 1, otherwise - // just decrement its count - int i = value.intValue(); - if (i == 1) { - listenerMap.remove(listener); - } else { - assert i > 1; - listenerMap.put(listener, i - 1); - } - } - } - } - } - // LoggerContext maps from AppContext private WeakHashMap contextsMap = null; @@ -1404,27 +1317,6 @@ // Set levels on any pre-existing loggers, based on the new properties. setLevelsOnExistingLoggers(); - // Notify any interested parties that our properties have changed. - // We first take a copy of the listener map so that we aren't holding any - // locks when calling the listeners. - Map listeners = null; - synchronized (listenerMap) { - if (!listenerMap.isEmpty()) - listeners = new HashMap<>(listenerMap); - } - if (listeners != null) { - assert Beans.isBeansPresent(); - Object ev = Beans.newPropertyChangeEvent(LogManager.class, null, null, null); - for (Map.Entry entry : listeners.entrySet()) { - Object listener = entry.getKey(); - int count = entry.getValue().intValue(); - for (int i = 0; i < count; i++) { - Beans.invokePropertyChange(listener, ev); - } - } - } - - // Note that we need to reinitialize global handles when // they are first referenced. synchronized (this) { @@ -1713,101 +1605,4 @@ } return loggingMXBean; } - - /** - * A class that provides access to the java.beans.PropertyChangeListener - * and java.beans.PropertyChangeEvent without creating a static dependency - * on java.beans. This class can be removed once the addPropertyChangeListener - * and removePropertyChangeListener methods are removed. - */ - private static class Beans { - private static final Class propertyChangeListenerClass = - getClass("java.beans.PropertyChangeListener"); - - private static final Class propertyChangeEventClass = - getClass("java.beans.PropertyChangeEvent"); - - private static final Method propertyChangeMethod = - getMethod(propertyChangeListenerClass, - "propertyChange", - propertyChangeEventClass); - - private static final Constructor propertyEventCtor = - getConstructor(propertyChangeEventClass, - Object.class, - String.class, - Object.class, - Object.class); - - private static Class getClass(String name) { - try { - return Class.forName(name, true, Beans.class.getClassLoader()); - } catch (ClassNotFoundException e) { - return null; - } - } - private static Constructor getConstructor(Class c, Class... types) { - try { - return (c == null) ? null : c.getDeclaredConstructor(types); - } catch (NoSuchMethodException x) { - throw new AssertionError(x); - } - } - - private static Method getMethod(Class c, String name, Class... types) { - try { - return (c == null) ? null : c.getMethod(name, types); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } - } - - /** - * Returns {@code true} if java.beans is present. - */ - static boolean isBeansPresent() { - return propertyChangeListenerClass != null && - propertyChangeEventClass != null; - } - - /** - * Returns a new PropertyChangeEvent with the given source, property - * name, old and new values. - */ - static Object newPropertyChangeEvent(Object source, String prop, - Object oldValue, Object newValue) - { - try { - return propertyEventCtor.newInstance(source, prop, oldValue, newValue); - } catch (InstantiationException | IllegalAccessException x) { - throw new AssertionError(x); - } catch (InvocationTargetException x) { - Throwable cause = x.getCause(); - if (cause instanceof Error) - throw (Error)cause; - if (cause instanceof RuntimeException) - throw (RuntimeException)cause; - throw new AssertionError(x); - } - } - - /** - * Invokes the given PropertyChangeListener's propertyChange method - * with the given event. - */ - static void invokePropertyChange(Object listener, Object ev) { - try { - propertyChangeMethod.invoke(listener, ev); - } catch (IllegalAccessException x) { - throw new AssertionError(x); - } catch (InvocationTargetException x) { - Throwable cause = x.getCause(); - if (cause instanceof Error) - throw (Error)cause; - if (cause instanceof RuntimeException) - throw (RuntimeException)cause; - throw new AssertionError(x); - } - } - } } diff -r 8dc8af2df113 -r b7163958d6d9 jdk/test/TEST.groups --- a/jdk/test/TEST.groups Sat Dec 14 20:36:10 2013 -0800 +++ b/jdk/test/TEST.groups Sun Dec 15 08:11:41 2013 +0000 @@ -357,8 +357,6 @@ java/security/Security/ClassLoaderDeadlock/ClassLoaderDeadlock.sh \ java/security/Security/ClassLoaderDeadlock/Deadlock.sh \ java/util/jar/Manifest/CreateManifest.java \ - java/util/logging/Listeners.java \ - java/util/logging/ListenersWithSM.java \ java/util/logging/TestMainAppContext.java \ java/util/ResourceBundle/Control/Bug6530694.java \ java/text/Bidi/BidiConformance.java \ diff -r 8dc8af2df113 -r b7163958d6d9 jdk/test/java/util/logging/Listeners.java --- a/jdk/test/java/util/logging/Listeners.java Sat Dec 14 20:36:10 2013 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 7192275 - * @summary Basic test of addPropertyListener/removePropertyListener methods - * @run main/othervm Listeners - */ - -import java.util.logging.LogManager; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeEvent; - -public class Listeners { - - static void assertTrue(boolean result, String msg) { - if (!result) - throw new RuntimeException(msg); - } - - /** - * A {@code PropertyChangeListener} that counts the number of times that - * the {@code propertyChange} method is fired, and also checks that the - * event source is the expected (fixed) object. - */ - static class Listener implements PropertyChangeListener { - private final Object expectedSource; - private int fireCount; - - Listener(Object expectedSource) { - this.expectedSource = expectedSource; - } - - int fireCount() { - return fireCount; - } - - Listener reset() { - fireCount = 0; - return this; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - assertTrue(evt.getSource() == expectedSource, "Unexpected source"); - fireCount++; - } - } - - /** - * Tests that the given listeners are invoked the expected number of - * times. - */ - static void test(Listener[] listeners, int... expected) throws Exception { - // reset counts - for (Listener listener : listeners) { - listener.reset(); - } - - // re-reading configuration causes events to be fired - LogManager.getLogManager().readConfiguration(); - - // check event listeners invoked as expected - for (int i = 0; i < expected.length; i++) { - assertTrue(listeners[i].fireCount() == expected[i], - "Unexpected event count"); - } - } - - @SuppressWarnings("deprecation") - public static void main(String[] args) throws Exception { - LogManager logman = LogManager.getLogManager(); - - Listener[] listeners = new Listener[2]; - Listener listener1 = listeners[0] = new Listener(LogManager.class); - Listener listener2 = listeners[1] = new Listener(LogManager.class); - - // add listeners - logman.addPropertyChangeListener(listener1); - test(listeners, 1, 0); - - logman.addPropertyChangeListener(listener1); - test(listeners, 2, 0); - - logman.addPropertyChangeListener(listener2); - test(listeners, 2, 1); - - // null handling to check for impact on the existing registrations - try { - logman.addPropertyChangeListener(null); - assertTrue(false, "NullPointerException expected"); - } catch (NullPointerException expected) { } - test(listeners, 2, 1); - - logman.removePropertyChangeListener(null); // no-op - test(listeners, 2, 1); - - // remove listeners - logman.removePropertyChangeListener(listener1); - test(listeners, 1, 1); - - logman.removePropertyChangeListener(listener1); - test(listeners, 0, 1); - - logman.removePropertyChangeListener(listener1); // no-op - test(listeners, 0, 1); - - logman.removePropertyChangeListener(listener2); - test(listeners, 0, 0); - - logman.removePropertyChangeListener(listener2); // no-op - test(listeners, 0, 0); - } -} diff -r 8dc8af2df113 -r b7163958d6d9 jdk/test/java/util/logging/ListenersWithSM.java --- a/jdk/test/java/util/logging/ListenersWithSM.java Sat Dec 14 20:36:10 2013 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* @test - * @bug 7192275 - * @summary Basic test of addPropertyListener/removePropertyListener methods - * @run main/othervm ListenersWithSM grant - * @run main/othervm ListenersWithSM deny - */ - -import java.nio.file.Paths; -import java.util.logging.LogManager; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeEvent; - -public class ListenersWithSM { - - @SuppressWarnings("deprecation") - public static void main(String[] args) throws Exception { - boolean granted = args[0].equals("grant"); - - // need to get reference to LogManager before setting SecurityManager - LogManager logman = LogManager.getLogManager(); - - // set policy and enable security manager - if (granted) { - String testSrc = System.getProperty("test.src"); - if (testSrc == null) - testSrc = "."; - System.setProperty("java.security.policy", - Paths.get(testSrc).resolve("java.policy").toString()); - } - System.setSecurityManager(new SecurityManager()); - - PropertyChangeListener listener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - } - }; - - if (granted) { - // permission granted, no security exception expected - logman.addPropertyChangeListener(listener); - logman.removePropertyChangeListener(listener); - } else { - // denied - try { - logman.addPropertyChangeListener(listener); - throw new RuntimeException("SecurityException expected"); - } catch (SecurityException expected) { } - try { - logman.removePropertyChangeListener(listener); - throw new RuntimeException("SecurityException expected"); - } catch (SecurityException expected) { } - } - } -} diff -r 8dc8af2df113 -r b7163958d6d9 jdk/test/java/util/logging/java.policy --- a/jdk/test/java/util/logging/java.policy Sat Dec 14 20:36:10 2013 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -grant { - permission java.util.logging.LoggingPermission "control"; -}; diff -r 8dc8af2df113 -r b7163958d6d9 jdk/test/tools/pack200/NoBeans.java --- a/jdk/test/tools/pack200/NoBeans.java Sat Dec 14 20:36:10 2013 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* @test - * @bug 8004931 - * @compile NoBeans.java - * @summary A compile-only test to ensure that implementations of Packer - * and Unpacker can be compiled without implementating the - * addPropertyChangeListener and removePropertyChangeListener methods. - */ - -import java.io.*; -import java.util.*; -import java.util.jar.*; - -public class NoBeans { - - static class MyPacker implements Pack200.Packer { - public SortedMap properties() { return null; } - public void pack(JarFile in, OutputStream out) { } - public void pack(JarInputStream in, OutputStream out) { } - } - - static class MyUnpacker implements Pack200.Unpacker { - public SortedMap properties() { return null; } - public void unpack(InputStream in, JarOutputStream out) { } - public void unpack(File in, JarOutputStream out) { } - } -} diff -r 8dc8af2df113 -r b7163958d6d9 jdk/test/tools/pack200/Reflect.java --- a/jdk/test/tools/pack200/Reflect.java Sat Dec 14 20:36:10 2013 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* @test - * @summary Invoke getDeclaredMethods on Packer and Unpacker to ensure - * that all types referenced in the method signatures is present. - */ - -import java.util.jar.Pack200; -import java.util.jar.Pack200.Packer; -import java.util.jar.Pack200.Unpacker; -import java.lang.reflect.Method; - -public class Reflect { - static void printMethods(Class c) { - System.out.println(c); - for (Method m: c.getDeclaredMethods()) { - System.out.println(" " + m); - } - } - public static void main(String[] args) { - printMethods(Pack200.Packer.class); - printMethods(Pack200.Unpacker.class); - printMethods(Pack200.newPacker().getClass()); - printMethods(Pack200.newUnpacker().getClass()); - } -}