Merge
authortbell
Sat, 05 Jul 2008 23:29:16 -0700
changeset 832 5484c7a35278
parent 798 75b3a644ef91 (current diff)
parent 831 50f701930577 (diff)
child 834 dc74d4ddc28e
Merge
jdk/src/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java
jdk/src/share/classes/com/sun/tools/jdi/EventSetImpl.java
--- a/jdk/src/share/back/eventFilter.c	Fri Jul 04 14:41:34 2008 -0700
+++ b/jdk/src/share/back/eventFilter.c	Sat Jul 05 23:29:16 2008 -0700
@@ -492,14 +492,17 @@
                   char *sourceName = 0;
                   jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,GetSourceFileName)
                                             (gdata->jvmti, clazz, &sourceName);
-                  if (error == JVMTI_ERROR_NONE) {
-                      if (sourceName == 0 || !patternStringMatch(sourceName, desiredNamePattern)) {
-                        /* We have no match */
-                        jvmtiDeallocate(sourceName);
-                        return JNI_FALSE;
-                      }
+                  if (error == JVMTI_ERROR_NONE &&
+                      sourceName != 0 &&
+                      patternStringMatch(sourceName, desiredNamePattern)) {
+                          // got a hit - report the event
+                          jvmtiDeallocate(sourceName);
+                          break;
                   }
+                  // We have no match, we have no source file name,
+                  // or we got a JVM TI error. Don't report the event.
                   jvmtiDeallocate(sourceName);
+                  return JNI_FALSE;
               }
               break;
           }
--- a/jdk/src/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java	Fri Jul 04 14:41:34 2008 -0700
+++ b/jdk/src/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java	Sat Jul 05 23:29:16 2008 -0700
@@ -686,7 +686,7 @@
                     final String msg =
                         "Cannot convert SortedSet with non-null comparator: " +
                         comparator;
-                    throw new OpenDataException(msg);
+                    throw openDataException(msg, new IllegalArgumentException(msg));
                 }
             }
             final Object[] openArray = (Object[])
@@ -800,7 +800,7 @@
                     final String msg =
                         "Cannot convert SortedMap with non-null comparator: " +
                         comparator;
-                    throw new OpenDataException(msg);
+                    throw openDataException(msg, new IllegalArgumentException(msg));
                 }
             }
             final TabularType tabularType = (TabularType) getOpenType();
--- a/jdk/src/share/classes/com/sun/tools/jdi/EventSetImpl.java	Fri Jul 04 14:41:34 2008 -0700
+++ b/jdk/src/share/classes/com/sun/tools/jdi/EventSetImpl.java	Sat Jul 05 23:29:16 2008 -0700
@@ -208,8 +208,9 @@
         }
 
         public String toString() {
-            return eventName() + "@" + location().toString() +
-                                 " in thread " + thread().name();
+            return eventName() + "@" +
+                   ((location() == null) ? " null" : location().toString()) +
+                   " in thread " + thread().name();
         }
     }
 
--- a/jdk/test/com/sun/jdi/SourceNameFilterTest.java	Fri Jul 04 14:41:34 2008 -0700
+++ b/jdk/test/com/sun/jdi/SourceNameFilterTest.java	Sat Jul 05 23:29:16 2008 -0700
@@ -23,7 +23,7 @@
 
 /**
  *  @test
- *  @bug 4836939
+ *  @bug 4836939 6646613
  *  @summary JDI add addSourceNameFilter to ClassPrepareRequest
  *
  *  @author jjh
@@ -31,7 +31,11 @@
  *  @run build TestScaffold VMConnection TargetListener TargetAdapter
  *  @run compile -g SourceNameFilterTest.java
  *  @run main SourceNameFilterTest
+ *  @run compile -g:none SourceNameFilterTest.java
+ *  @run main SourceNameFilterTest
  */
+// The compile -g:none suppresses the lineNumber table to trigger bug 6646613.
+
 import com.sun.jdi.*;
 import com.sun.jdi.event.*;
 import com.sun.jdi.request.*;
@@ -84,7 +88,6 @@
     boolean gotEvent1 = false;
     boolean gotEvent2 = false;
     boolean gotEvent3 = false;
-
     ClassPrepareRequest cpReq;
     boolean shouldResume = false;
     SourceNameFilterTest (String args[]) {
@@ -151,6 +154,18 @@
          */
         BreakpointEvent bpe = startToMain("SourceNameFilterTarg");
         targetClass = bpe.location().declaringType();
+        boolean noSourceName = false;
+        try {
+            targetClass.sourceName();
+        } catch (AbsentInformationException ee) {
+            noSourceName = true;
+        }
+        if (noSourceName) {
+            println("-- Running with no source names");
+        } else {
+            println("-- Running with source names");
+        }
+
         mainThread = bpe.thread();
         EventRequestManager erm = vm().eventRequestManager();
         addListener(this);
@@ -175,7 +190,9 @@
 
         /*
          * This should cause us to get a class prepare event for
-         * LoadedLater3
+         * LoadedLater3 except in the case where -g:none
+         * was used to compile so that there is no LineNumberTable
+         * and therefore, no source name for the class.
          */
         cpReq = erm.createClassPrepareRequest();
         cpReq.addSourceNameFilter("SourceNameFilterTest.java");
@@ -186,17 +203,21 @@
 
         if (!gotEvent1) {
             failure("failure: Did not get a class prepare request " +
-                    "for Loadedlater1");
+                    "for LoadedLater1");
         }
 
         if (gotEvent2) {
             failure("failure: Did get a class prepare request " +
-                    "for Loadedlater2");
+                    "for LoadedLater2");
         }
 
-        if (!gotEvent3) {
+        if (gotEvent3 && noSourceName) {
+            failure("failure: Did get a class prepare request " +
+                    "for LoadedLater3");
+        }
+        else if (!gotEvent3 && !noSourceName) {
             failure("failure: Did not get a class prepare request " +
-                    "for Loadedlater3");
+                    "for LoadedLater3");
         }
 
         /*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/management/mxbean/ComparatorExceptionTest.java	Sat Jul 05 23:29:16 2008 -0700
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6601652
+ * @summary Test exception when SortedMap or SortedSet has non-null Comparator
+ * @author Eamonn McManus
+ */
+
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+public class ComparatorExceptionTest {
+    public static interface TestMXBean {
+        public SortedSet<String> getSortedSet();
+        public SortedMap<String, String> getSortedMap();
+    }
+
+    public static class TestImpl implements TestMXBean {
+        public SortedSet<String> getSortedSet() {
+            return new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+        }
+
+        public SortedMap<String, String> getSortedMap() {
+            return new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
+        }
+    }
+
+    private static String failure;
+
+    private static void fail(String why) {
+        failure = "FAILED: " + why;
+        System.out.println(failure);
+    }
+
+    public static void main(String[] args) throws Exception {
+        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
+        ObjectName name = new ObjectName("a:b=c");
+        mbs.registerMBean(new TestImpl(), name);
+
+        for (String attr : new String[] {"SortedSet", "SortedMap"}) {
+            try {
+                Object value = mbs.getAttribute(name, attr);
+                fail("get " + attr + " did not throw exception");
+            } catch (Exception e) {
+                Throwable t = e;
+                while (!(t instanceof IllegalArgumentException)) {
+                    if (t == null)
+                        break;
+                    t = t.getCause();
+                }
+                if (t != null)
+                    System.out.println("Correct exception for " + attr);
+                else {
+                    fail("get " + attr + " got wrong exception");
+                    e.printStackTrace(System.out);
+                }
+            }
+        }
+
+        if (failure != null)
+            throw new Exception(failure);
+    }
+}
--- a/jdk/test/javax/management/mxbean/MXBeanTest.java	Fri Jul 04 14:41:34 2008 -0700
+++ b/jdk/test/javax/management/mxbean/MXBeanTest.java	Sat Jul 05 23:29:16 2008 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 6175517 6278707 6318827 6305746 6392303
+ * @bug 6175517 6278707 6318827 6305746 6392303 6600709
  * @summary General MXBean test.
  * @author Eamonn McManus
  * @run clean MXBeanTest MerlinMXBean TigerMXBean
@@ -40,7 +40,8 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import javax.management.Attribute;
+import java.util.Map;
+import java.util.SortedMap;
 import javax.management.JMX;
 import javax.management.MBeanAttributeInfo;
 import javax.management.MBeanInfo;
@@ -55,10 +56,6 @@
 import javax.management.openmbean.ArrayType;
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.CompositeDataInvocationHandler;
-import javax.management.openmbean.OpenMBeanAttributeInfo;
-import javax.management.openmbean.OpenMBeanInfo;
-import javax.management.openmbean.OpenMBeanOperationInfo;
-import javax.management.openmbean.OpenMBeanParameterInfo;
 import javax.management.openmbean.OpenType;
 import javax.management.openmbean.SimpleType;
 import javax.management.openmbean.TabularData;
@@ -81,10 +78,8 @@
 
         if (failures == 0)
             System.out.println("Test passed");
-        else {
-            System.out.println("TEST FAILURES: " + failures);
-            System.exit(1);
-        }
+        else
+            throw new Exception("TEST FAILURES: " + failures);
     }
 
     private static int failures = 0;
@@ -561,6 +556,11 @@
                 return false;
             return deepEqual(o1, o2, namedMXBeans);
         }
+        if (o1 instanceof Map) {
+            if (!(o2 instanceof Map))
+                return false;
+            return equalMap((Map) o1, (Map) o2, namedMXBeans);
+        }
         if (o1 instanceof CompositeData && o2 instanceof CompositeData) {
             return compositeDataEqual((CompositeData) o1, (CompositeData) o2,
                                       namedMXBeans);
@@ -600,6 +600,21 @@
         return true;
     }
 
+    private static boolean equalMap(Map<?,?> m1, Map<?,?> m2,
+                                    NamedMXBeans namedMXBeans) {
+        if (m1.size() != m2.size())
+            return false;
+        if ((m1 instanceof SortedMap) != (m2 instanceof SortedMap))
+            return false;
+        for (Object k1 : m1.keySet()) {
+            if (!m2.containsKey(k1))
+                return false;
+            if (!equal(m1.get(k1), m2.get(k1), namedMXBeans))
+                return false;
+        }
+        return true;
+    }
+
     // This is needed to work around a bug (5095277)
     // in CompositeDataSupport.equals
     private static boolean compositeDataEqual(CompositeData cd1,
@@ -655,7 +670,7 @@
     /* I wanted to call this method toString(Object), but oddly enough
        this meant that I couldn't call it from the inner class
        MXBeanImplInvocationHandler, because the inherited Object.toString()
-       prevented that.  Surprising behaviour.  */
+       prevented that.  */
     static String string(Object o) {
         if (o == null)
             return "null";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/management/mxbean/SameObjectTwoNamesTest.java	Sat Jul 05 23:29:16 2008 -0700
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test SameObjectTwoNamesTest.java
+ * @bug 6283873
+ * @summary Check that registering the same MXBean under two different
+ * names produces an exception
+ * @author Alexander Shusherov
+ * @author Eamonn McManus
+ * @run main SameObjectTwoNamesTest
+ * @run main/othervm -Djmx.mxbean.multiname=true SameObjectTwoNamesTest
+ */
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+public class SameObjectTwoNamesTest {
+
+    public static void main(String[] args) throws Exception {
+        boolean expectException =
+                (System.getProperty("jmx.mxbean.multiname") == null);
+        try {
+            ObjectName objectName1 = new ObjectName("test:index=1");
+            ObjectName objectName2 = new ObjectName("test:index=2");
+            MBeanServer mbs = MBeanServerFactory.createMBeanServer();
+            MXBC_SimpleClass01 mxBeanObject = new MXBC_SimpleClass01();
+
+            mbs.registerMBean(mxBeanObject, objectName1);
+
+            mbs.registerMBean(mxBeanObject, objectName2);
+
+            if (expectException) {
+                throw new Exception("TEST FAILED: " +
+                        "InstanceAlreadyExistsException was not thrown");
+            } else
+                System.out.println("Correctly got no exception with compat property");
+        } catch (InstanceAlreadyExistsException e) {
+            if (expectException) {
+                System.out.println("Got expected InstanceAlreadyExistsException:");
+                e.printStackTrace(System.out);
+            } else {
+                throw new Exception(
+                        "TEST FAILED: Got exception even though compat property set", e);
+            }
+        }
+        System.out.println("TEST PASSED");
+    }
+
+    public interface MXBC_Simple01MXBean {}
+
+    public static class MXBC_SimpleClass01 implements MXBC_Simple01MXBean {}
+
+}