8004931: add/removePropertyChangeListener should not exist in subset Profiles of Java SE

Reviewed-by: dholmes, mchung, ksrini
This commit is contained in:
Alan Bateman 2013-01-21 23:23:12 -05:00
parent 50ccbb6018
commit 3ca765dfbd
7 changed files with 305 additions and 5 deletions
jdk
make/tools/src/build/tools
makefiles
src/share/classes/java/util
test
java/util/logging
tools/pack200

@ -0,0 +1,117 @@
/*
* 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.io.IOException;
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.ClassReader;
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<String> 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);
}
}
}

@ -136,6 +136,10 @@ TOOL_OSX_TOBIN=$(JAVA) -Djava.awt.headless=true -cp $(JDK_OUTPUTDIR)/btclasses \
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
##########################################################################################
# Tools needed on solaris because OBJCOPY is broken.

@ -574,6 +574,13 @@ public abstract class Pack200 {
* Registers a listener for PropertyChange events on the properties map.
* This is typically used by applications to update a progress bar.
*
* <p> The default implementation of this method does nothing and has
* no side-effects.</p>
*
* <p><b>WARNING:</b> This method is omitted from the interface
* declaration in all subset Profiles of Java SE that do not include
* the {@code java.beans} package. </p>
* @see #properties
* @see #PROGRESS
* @param listener An object to be invoked when a property is changed.
@ -586,12 +593,20 @@ public abstract class Pack200 {
* property instead.
*/
@Deprecated
void addPropertyChangeListener(PropertyChangeListener listener) ;
default void addPropertyChangeListener(PropertyChangeListener listener) {
}
/**
* Remove a listener for PropertyChange events, added by
* the {@link #addPropertyChangeListener}.
*
* <p> The default implementation of this method does nothing and has
* no side-effects.</p>
*
* <p><b>WARNING:</b> This method is omitted from the interface
* declaration in all subset Profiles of Java SE that do not include
* the {@code java.beans} package. </p>
*
* @see #addPropertyChangeListener
* @param listener The PropertyChange listener to be removed.
* @deprecated The dependency on {@code PropertyChangeListener} creates
@ -600,8 +615,8 @@ public abstract class Pack200 {
* release.
*/
@Deprecated
void removePropertyChangeListener(PropertyChangeListener listener);
default void removePropertyChangeListener(PropertyChangeListener listener) {
}
}
/**
@ -718,6 +733,13 @@ public abstract class Pack200 {
* Registers a listener for PropertyChange events on the properties map.
* This is typically used by applications to update a progress bar.
*
* <p> The default implementation of this method does nothing and has
* no side-effects.</p>
*
* <p><b>WARNING:</b> This method is omitted from the interface
* declaration in all subset Profiles of Java SE that do not include
* the {@code java.beans} package. </p>
*
* @see #properties
* @see #PROGRESS
* @param listener An object to be invoked when a property is changed.
@ -730,12 +752,20 @@ public abstract class Pack200 {
* PROGRESS} property instead.
*/
@Deprecated
void addPropertyChangeListener(PropertyChangeListener listener) ;
default void addPropertyChangeListener(PropertyChangeListener listener) {
}
/**
* Remove a listener for PropertyChange events, added by
* the {@link #addPropertyChangeListener}.
*
* <p> The default implementation of this method does nothing and has
* no side-effects.</p>
*
* <p><b>WARNING:</b> This method is omitted from the interface
* declaration in all subset Profiles of Java SE that do not include
* the {@code java.beans} package. </p>
*
* @see #addPropertyChangeListener
* @param listener The PropertyChange listener to be removed.
* @deprecated The dependency on {@code PropertyChangeListener} creates
@ -744,7 +774,8 @@ public abstract class Pack200 {
* release.
*/
@Deprecated
void removePropertyChangeListener(PropertyChangeListener listener);
default void removePropertyChangeListener(PropertyChangeListener listener) {
}
}
// Private stuff....

@ -302,6 +302,10 @@ public class LogManager {
* the same event Listener results in multiple entries
* in the property event listener table.
*
* <p><b>WARNING:</b> This method is omitted from this class in all subset
* Profiles of Java SE that do not include the {@code java.beans} package.
* </p>
*
* @param l event listener
* @exception SecurityException if a security manager exists and if
* the caller does not have LoggingPermission("control").
@ -335,6 +339,10 @@ public class LogManager {
* <P>
* Returns silently if the given listener is not found.
*
* <p><b>WARNING:</b> This method is omitted from this class in all subset
* Profiles of Java SE that do not include the {@code java.beans} package.
* </p>
*
* @param l event listener (can be null)
* @exception SecurityException if a security manager exists and if
* the caller does not have LoggingPermission("control").

@ -0,0 +1,44 @@
/*
* 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
* @summary Invoke getDeclaredMethods on LogManager to ensure that
* all types referenced in the method signatures is present.
*/
import java.util.logging.LogManager;
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(java.util.logging.LogManager.class);
printMethods(java.util.logging.LogManager.getLogManager().getClass());
}
}

@ -0,0 +1,49 @@
/*
* 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<String,String> 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<String,String> properties() { return null; }
public void unpack(InputStream in, JarOutputStream out) { }
public void unpack(File in, JarOutputStream out) { }
}
}

@ -0,0 +1,47 @@
/*
* 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());
}
}