/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 4719923
* @summary Test that MBeanInfo.equals works even for mutable subclasses
* @author Eamonn McManus
* @run clean MBeanInfoEqualsTest
* @run build MBeanInfoEqualsTest
* @run main MBeanInfoEqualsTest
*/
/* Test that MBeanInfo and its referenced classes implement the equals
and hashCode methods correctly. These classes include some magic
to improve performance based on the classes' immutability. The
logic checks that any subclasses encountered remain immutable, and
falls back on less performant code if not. */
import javax.management.*;
public class MBeanInfoEqualsTest {
// Class just used for reflection
private static class Toy {
public Toy() {}
public void setA(int a) {}
public boolean isB() {return false;}
public void setB(boolean b) {}
public void run() {}
}
static {
try {
String.class});
String.class});
} catch (Exception e) {
throw new Error(e.getMessage());
}
}
private static final MBeanAttributeInfo
try {
} catch (IntrospectionException e) {
throw new Error(e.getMessage());
}
}
static final MBeanAttributeInfo
true, true, false),
true, true, false),
true, true, false),
true, true, false),
false, true, false),
true, true, false),
true, false, false),
false, true, false),
true, true, true),
true, false, true);
static final MBeanParameterInfo
static final MBeanConstructorInfo
new MBeanParameterInfo[0]),
c1a.getSignature()),
null),
c2a.getSignature()),
static final MBeanOperationInfo
null, "void",
static final MBeanNotificationInfo
"x.y.z",
"a notification info"),
"x.y.z",
"a notification info"),
"x.y.z",
"another notification info"),
n2a.getDescription()),
"x.y.zz",
"a notification info"),
"x.y.z",
"a notification info");
static final MBeanAttributeInfo[]
static final MBeanConstructorInfo[]
static final MBeanOperationInfo[]
static final MBeanNotificationInfo[]
static final MBeanInfo
xn1b),
xn1a),
{i7},
};
}
}
/* This class checks that the MBeanInfo.equals() method really
does call getClassName() etc rather than referring to its
private fields. */
this.description = description;
this.attributes = attributes;
this.constructors = constructors;
this.operations = operations;
this.notifications = notifications;
}
return className;
}
return description;
}
return attributes;
}
return operations;
}
return constructors;
}
return notifications;
}
}
boolean ok = true;
/* The equivs array is an array of equivalence classes. The members
of each equivalence class must be equal among themselves.
Each member of each equivalence class must be different from
each member of each other equivalence class. */
continue;
}
}
if (ok)
return ok;
}
/* We could simplify this test to compare every element with every
other and choose whether they are supposed to be the same based
on whether they are in the same equivalence class. A bit
simpler, but so what. */
boolean ok = true;
": !obj[" + i +
"].equals(obj[" + j + "])");
ok = false;
}
": obj[" + i +
"].hashCode() != obj[" + j +
"].hashCode()");
ok = false;
}
}
}
return ok;
}
boolean ok = true;
i + "].equals(obj[" + j + "])");
ok = false;
}
}
}
return ok;
}
boolean ok = true;
if (ok) {
} else {
}
}
}