8139725: Backout escaped partial fix for JDK-7199353

Reviewed-by: alanb
This commit is contained in:
Jaroslav Bachorik 2015-10-16 06:29:36 +02:00
parent fe396d8bf4
commit 4f7119fdef
13 changed files with 38 additions and 223 deletions

View File

@ -60,7 +60,6 @@ import java.util.WeakHashMap;
import javax.management.JMX;
import javax.management.ObjectName;
import javax.management.ConstructorProperties;
import javax.management.openmbean.ArrayType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataInvocationHandler;
@ -1142,19 +1141,10 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory {
super(targetClass, itemNames);
}
private String[] getConstPropValues(Constructor<?> ctr) {
// is constructor annotated by javax.management.ConstructorProperties ?
ConstructorProperties ctrProps = ctr.getAnnotation(ConstructorProperties.class);
if (ctrProps != null) {
return ctrProps.value();
} else {
// try the legacy java.beans.ConstructorProperties annotation
String[] vals = JavaBeansAccessor.getConstructorPropertiesValue(ctr);
return vals;
}
}
String applicable(Method[] getters) throws InvalidObjectException {
if (!JavaBeansAccessor.isAvailable())
return "@ConstructorProperties annotation not available";
Class<?> targetClass = getTargetClass();
Constructor<?>[] constrs = targetClass.getConstructors();
@ -1162,7 +1152,7 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory {
List<Constructor<?>> annotatedConstrList = newList();
for (Constructor<?> constr : constrs) {
if (Modifier.isPublic(constr.getModifiers())
&& getConstPropValues(constr) != null)
&& JavaBeansAccessor.getConstructorPropertiesValue(constr) != null)
annotatedConstrList.add(constr);
}
@ -1191,7 +1181,7 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory {
// so we can test unambiguity.
Set<BitSet> getterIndexSets = newSet();
for (Constructor<?> constr : annotatedConstrList) {
String[] propertyNames = getConstPropValues(constr);
String[] propertyNames = JavaBeansAccessor.getConstructorPropertiesValue(constr);
Type[] paramTypes = constr.getGenericParameterTypes();
if (paramTypes.length != propertyNames.length) {

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2006, 2015 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 javax.management;
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
* <p>
* An annotation on a constructor that shows how the parameters of
* that constructor correspond to the constructed object's getter
* methods. For example:
* </p>
* <blockquote>
* <pre>
* public class MemoryUsage {
* // standard JavaBean conventions with getters
* <b>&#64;ConstructorProperties({"init", "used", "committed", "max"})</b>
* public MemoryUsage(long init, long used,
* long committed, long max) {...}
* long getInit() {...}
* long getUsed() {...}
* long getCommitted() {...}
* long getMax() {...}
* }
* </pre>
* </blockquote>
* <p>
* The annotation shows that the first parameter of the constructor
* can be retrieved with the {@code getInit()} method, the second one with
* the {@code getUsed()} method, and so on. Since parameter names are not in
* general available at runtime, without the annotation there would be
* no way of knowing which parameter corresponds to which property.
* </p>
* <p>
* If a constructor is annotated by the both {@code @java.beans.ConstructorProperties}
* and {@code @javax.management.annotation.ConstructorProperties} annotations
* the JMX introspection will give an absolute precedence to the later one.
* </p>
*
* @since 1.9
*/
@Documented @Target(CONSTRUCTOR) @Retention(RUNTIME)
public @interface ConstructorProperties {
/**
<p>The getter names.</p>
@return the getter names corresponding to the parameters in the
annotated constructor.
*/
String[] value();
}

View File

@ -168,8 +168,8 @@ public class MemoryUsage {
<p>The definitions are the same in the two cases, except
that with the MXBean, <code>MemoryUsage</code> no longer needs to
be marked <code>Serializable</code> (though it can be). On
the other hand, we have added a {@link ConstructorProperties &#64;ConstructorProperties}
annotation to link the constructor parameters to the corresponding getters.
the other hand, we have added a {@code @ConstructorProperties} annotation
to link the constructor parameters to the corresponding getters.
We will see more about this below.</p>
<p><code>MemoryUsage</code> is a <em>model-specific class</em>.
@ -850,16 +850,10 @@ public interface ModuleMXBean {
<em>J</em>.</p></li>
<li><p>Otherwise, if <em>J</em> has at least one public
constructor with either {@link javax.management.ConstructorProperties
&#64;javax.management.ConstructorProperties} or
{@code @java.beans.ConstructoProperties} annotation, then one of those
constructors (not necessarily always the same one) will be called to
reconstruct an instance of <em>J</em>.
If a constructor is annotated with both
{@code @javax.management.ConstructorProperties} and
{@code @java.beans.ConstructorProperties},
{@code @javax.management.ConstructorProperties} will be used and
{@code @java.beans.ConstructorProperties} will be ignored.
constructor with a {@link java.beans.ConstructorProperties
ConstructorProperties} annotation, then one
of those constructors (not necessarily always the same one)
will be called to reconstruct an instance of <em>J</em>.
Every such annotation must list as many strings as the
constructor has parameters; each string must name a property
corresponding to a getter of <em>J</em>; and the type of this
@ -915,9 +909,8 @@ public interface ModuleMXBean {
<li><p>Otherwise, <em>J</em> is not reconstructible.</p></li>
</ol>
<p>When {@code @java.beans.ConstructorProperties} is used then rule 2 is not
applicable to subset Profiles of Java SE that do not include the
{@code java.beans} package. When targeting a runtime that does
<p>Rule 2 is not applicable to subset Profiles of Java SE that do not
include the {@code java.beans} package. When targeting a runtime that does
not include the {@code java.beans} package, and where there is a mismatch
between the compile-time and runtime environment whereby <em>J</em> is
compiled with a public constructor and the {@code ConstructorProperties}

View File

@ -27,7 +27,8 @@
* @summary Test that having a security manager doesn't trigger a
* NotCompliantMBeanException
* @author Daniel Fuchs, Yves Joan
* @modules java.management
* @modules java.desktop
* java.management
* @run clean AnnotationSecurityTest Described UnDescribed DescribedMBean
* UnDescribedMBean SqeDescriptorKey DescribedMX DescribedMXBean
* @run build AnnotationSecurityTest Described UnDescribed DescribedMBean
@ -39,8 +40,13 @@
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.management.ManagementFactory;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/**

View File

@ -25,7 +25,7 @@
*
* Used by AnnotationSecurityTest.java
**/
import javax.management.ConstructorProperties;
import java.beans.ConstructorProperties;
/**
* An MBean used by AnnotationSecurityTest.java

View File

@ -25,7 +25,7 @@
*
* Used by AnnotationSecurityTest.java
**/
import javax.management.ConstructorProperties;
import java.beans.ConstructorProperties;
/**
* An MXBean used by AnnotationSecurityTest.java

View File

@ -1,105 +0,0 @@
/*
* Copyright (c) 2015, 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.
*/
import java.beans.ConstructorProperties;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
/*
* @test
* @bug 7199353
* @summary Asserts that 'java.beans.ConstructorProperties' annotation is still
* recognized and properly handled for custom types mapped to open types.
* Also, makes sure that if the same constructor is annotated by both
* j.b.ConstructorProperties and j.m.ConstructorProperties annotations
* only j.m.ConstructorProperties annotation is considered.
* @author Jaroslav Bachorik
* @modules java.management
* java.desktop
* @run main LegacyConstructorPropertiesTest
*/
public class LegacyConstructorPropertiesTest {
public static class CustomType {
private String name;
private int value;
@ConstructorProperties({"name", "value"})
public CustomType(String name, int value) {
this.name = name;
this.value = value;
}
// if @java.beans.ConstructorProperties would be used
// the introspector would choke on this
@ConstructorProperties("noname")
@javax.management.ConstructorProperties("name")
public CustomType(String name) {
this.name = name;
this.value = -1;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
public static interface CustomMXBean {
public CustomType getProp();
public void setProp(CustomType prop);
}
public static final class Custom implements CustomMXBean {
private CustomType prop;
@Override
public CustomType getProp() {
return prop;
}
@Override
public void setProp(CustomType prop) {
this.prop = prop;
}
}
public static void main(String[] args) throws Exception {
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
CustomMXBean mbean = new Custom();
mbs.registerMBean(mbean, ObjectName.getInstance("test:type=Custom"));
}
}

View File

@ -26,13 +26,15 @@
* @bug 6175517 6278707
* @summary Test that ambiguous ConstructorProperties annotations are detected.
* @author Eamonn McManus
* @modules java.management
* @modules java.desktop
* java.management
* @run clean AmbiguousConstructorTest
* @run build AmbiguousConstructorTest
* @run main AmbiguousConstructorTest
*/
import javax.management.ConstructorProperties;
import java.beans.ConstructorProperties;
import java.io.InvalidObjectException;
import javax.management.*;
public class AmbiguousConstructorTest {

View File

@ -26,10 +26,11 @@
* @bug 6713777
* @summary Test that exception messages include all relevant information
* @author Eamonn McManus
* @modules java.management
* @modules java.desktop
* java.management
*/
import javax.management.ConstructorProperties;
import java.beans.ConstructorProperties;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

View File

@ -25,7 +25,8 @@
* @bug 6482247
* @summary Test that creating MXBeans does not introduce memory leaks.
* @author Eamonn McManus
* @modules java.management
* @modules java.desktop
* java.management
* @run build LeakTest RandomMXBeanTest MerlinMXBean TigerMXBean
* @run main LeakTest
*/

View File

@ -27,7 +27,8 @@
* @summary General MXBean test.
* @author Eamonn McManus
* @author Jaroslav Bachorik
* @modules java.management
* @modules java.desktop
* java.management
* @run clean MXBeanTest MerlinMXBean TigerMXBean
* @run build MXBeanTest MerlinMXBean TigerMXBean
* @run main MXBeanTest

View File

@ -26,13 +26,14 @@
* @bug 6175517
* @summary Test the PropertyNames annotation with MXBeans
* @author Eamonn McManus
* @modules java.management
* @modules java.desktop
* java.management
* @run clean PropertyNamesTest
* @run build PropertyNamesTest
* @run main PropertyNamesTest
*/
import javax.management.ConstructorProperties;
import java.beans.ConstructorProperties;
import java.util.Collections;
import java.util.List;
import javax.management.JMX;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2008, 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
@ -21,7 +21,7 @@
* questions.
*/
import javax.management.ConstructorProperties;
import java.beans.ConstructorProperties;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;