Merge
authorlana
Wed, 19 Sep 2012 12:41:54 -0700
changeset 13823 9a7055463e06
parent 13783 539a1187467a (diff)
parent 13822 0b0453f12ab2 (current diff)
child 13824 aadf5d358153
Merge
jdk/src/share/classes/sun/management/LockDataConverter.java
jdk/src/share/classes/sun/management/LockDataConverterMXBean.java
jdk/src/share/classes/sun/security/x509/CertificateIssuerUniqueIdentity.java
jdk/src/share/classes/sun/security/x509/CertificateSubjectUniqueIdentity.java
jdk/test/sun/misc/URLClassPath/ClassnameCharTest.sh
jdk/test/sun/net/www/httptest/HttpServer.java
jdk/test/sun/security/ssl/sun/net/www/httpstest/HttpServer.java
--- a/jdk/src/macosx/classes/sun/awt/SunToolkitSubclass.java	Wed Sep 19 14:55:40 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2011, 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 sun.awt;
-
-// This class exists only so we can flush the PostEventQueue for the right AppContext
-// The default flushPendingEvents only flushes the thread-local context, which is wrong.
-// c.f. 3746956
-public abstract class SunToolkitSubclass extends SunToolkit {
-    public static void flushPendingEvents(AppContext appContext) {
-        flushLock.lock();
-        PostEventQueue postEventQueue = (PostEventQueue)appContext.get("PostEventQueue");
-        if (postEventQueue != null) {
-            postEventQueue.flush();
-        }
-        flushLock.unlock();
-    }
-}
--- a/jdk/src/macosx/classes/sun/font/CFontManager.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/classes/sun/font/CFontManager.java	Wed Sep 19 12:41:54 2012 -0700
@@ -37,6 +37,7 @@
 import javax.swing.plaf.FontUIResource;
 
 import sun.awt.FontConfiguration;
+import sun.awt.HeadlessToolkit;
 import sun.lwawt.macosx.*;
 
 public class CFontManager extends SunFontManager {
@@ -342,9 +343,14 @@
     @Override
     public String getFontPath(boolean noType1Fonts) {
         // In the case of the Cocoa toolkit, since we go through NSFont, we dont need to register /Library/Fonts
-        if (Toolkit.getDefaultToolkit() instanceof LWCToolkit) {
+        Toolkit tk = Toolkit.getDefaultToolkit();
+        if (tk instanceof HeadlessToolkit) {
+            tk = ((HeadlessToolkit)tk).getUnderlyingToolkit();
+        }
+        if (tk instanceof LWCToolkit) {
             return "";
         }
+
         // X11 case
         return "/Library/Fonts";
     }
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java	Wed Sep 19 12:41:54 2012 -0700
@@ -134,7 +134,7 @@
         boolean postsTyped = false;
 
         char testChar = KeyEvent.CHAR_UNDEFINED;
-        char testDeadChar = 0;
+        boolean isDeadChar = (chars!= null && chars.length() == 0);
 
         if (isFlagsChangedEvent) {
             int[] in = new int[] {modifierFlags, keyCode};
@@ -150,14 +150,18 @@
                 testChar = chars.charAt(0);
             }
 
-            int[] in = new int[] {testChar, testDeadChar, modifierFlags, keyCode};
-            int[] out = new int[2]; // [jkeyCode, jkeyLocation]
+            int[] in = new int[] {testChar, isDeadChar ? 1 : 0, modifierFlags, keyCode};
+            int[] out = new int[3]; // [jkeyCode, jkeyLocation, deadChar]
 
             postsTyped = NSEvent.nsToJavaKeyInfo(in, out);
             if (!postsTyped) {
                 testChar = KeyEvent.CHAR_UNDEFINED;
             }
 
+            if(isDeadChar){
+                testChar = (char) out[2];
+            }
+
             jkeyCode = out[0];
             jkeyLocation = out[1];
             jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Wed Sep 19 12:41:54 2012 -0700
@@ -536,7 +536,7 @@
             SunToolkit.postEvent(appContext, invocationEvent);
 
             // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
-            sun.awt.SunToolkitSubclass.flushPendingEvents(appContext);
+            SunToolkit.flushPendingEvents(appContext);
         } else {
             // This should be the equivalent to EventQueue.invokeAndWait
             ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
@@ -561,7 +561,7 @@
             SunToolkit.postEvent(appContext, invocationEvent);
 
             // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
-            sun.awt.SunToolkitSubclass.flushPendingEvents(appContext);
+            SunToolkit.flushPendingEvents(appContext);
         } else {
             // This should be the equivalent to EventQueue.invokeAndWait
             ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
--- a/jdk/src/macosx/native/sun/awt/AWTEvent.h	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/native/sun/awt/AWTEvent.h	Wed Sep 19 12:41:54 2012 -0700
@@ -33,5 +33,7 @@
 void DeliverJavaMouseEvent(JNIEnv *env, NSEvent *event, jobject peer);
 void SendAdditionalJavaEvents(JNIEnv *env, NSEvent *nsEvent, jobject peer);
 jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags);
+jint NsKeyModifiersToJavaModifiers(NSUInteger nsFlags, BOOL isExtMods);
+NSUInteger JavaModifiersToNsKeyModifiers(jint javaModifiers, BOOL isExtMods);
 
 #endif /* __AWTEVENT_H */
--- a/jdk/src/macosx/native/sun/awt/AWTEvent.m	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/native/sun/awt/AWTEvent.m	Wed Sep 19 12:41:54 2012 -0700
@@ -26,6 +26,7 @@
 #import <JavaNativeFoundation/JavaNativeFoundation.h>
 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
 #import <sys/time.h>
+#include <Carbon/Carbon.h>
 
 #import "LWCToolkit.h"
 #import "ThreadUtilities.h"
@@ -244,6 +245,7 @@
     //NSUInteger cgsRightMask;
     unsigned short leftKeyCode;
     unsigned short rightKeyCode;
+    jint javaExtMask;
     jint javaMask;
     jint javaKey;
 }
@@ -254,6 +256,7 @@
         0,
         0,
         0, // no Java equivalent
+        0, // no Java equivalent
         java_awt_event_KeyEvent_VK_CAPS_LOCK
     },
     {
@@ -263,6 +266,7 @@
         56,
         60,
         java_awt_event_InputEvent_SHIFT_DOWN_MASK,
+        java_awt_event_InputEvent_SHIFT_MASK,
         java_awt_event_KeyEvent_VK_SHIFT
     },
     {
@@ -272,6 +276,7 @@
         59,
         62,
         java_awt_event_InputEvent_CTRL_DOWN_MASK,
+        java_awt_event_InputEvent_CTRL_MASK,
         java_awt_event_KeyEvent_VK_CONTROL
     },
     {
@@ -281,6 +286,7 @@
         58,
         61,
         java_awt_event_InputEvent_ALT_DOWN_MASK,
+        java_awt_event_InputEvent_ALT_MASK,
         java_awt_event_KeyEvent_VK_ALT
     },
     {
@@ -290,6 +296,7 @@
         55,
         54,
         java_awt_event_InputEvent_META_DOWN_MASK,
+        java_awt_event_InputEvent_META_MASK,
         java_awt_event_KeyEvent_VK_META
     },
     // NSNumericPadKeyMask
@@ -298,10 +305,11 @@
         0,
         0,
         0, // no Java equivalent
+        0, // no Java equivalent
         java_awt_event_KeyEvent_VK_HELP
     },
     // NSFunctionKeyMask
-    {0, 0, 0, 0, 0}
+    {0, 0, 0, 0, 0, 0}
 };
 
 /*
@@ -371,26 +379,67 @@
     return nsChar;
 }
 
+static unichar NsGetDeadKeyChar(unsigned short keyCode)
+{
+    TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
+    CFDataRef uchr = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
+    const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout*)CFDataGetBytePtr(uchr);
+    // Carbon modifiers should be used instead of NSEvent modifiers
+    UInt32 modifierKeyState = (GetCurrentEventKeyModifiers() >> 8) & 0xFF;
+
+    if (keyboardLayout) {
+        UInt32 deadKeyState = 0;
+        UniCharCount maxStringLength = 255;
+        UniCharCount actualStringLength = 0;
+        UniChar unicodeString[maxStringLength];
+
+        // get the deadKeyState
+        OSStatus status = UCKeyTranslate(keyboardLayout,
+                                         keyCode, kUCKeyActionDown, modifierKeyState,
+                                         LMGetKbdType(), kUCKeyTranslateNoDeadKeysBit,
+                                         &deadKeyState,
+                                         maxStringLength,
+                                         &actualStringLength, unicodeString);
+
+        if (status == noErr && deadKeyState != 0) {
+            // Press SPACE to get the dead key char
+            status = UCKeyTranslate(keyboardLayout,
+                                    kVK_Space, kUCKeyActionDown, 0,
+                                    LMGetKbdType(), 0,
+                                    &deadKeyState,
+                                    maxStringLength,
+                                    &actualStringLength, unicodeString);
+
+            if (status == noErr && actualStringLength > 0) {
+                return unicodeString[0];
+            }
+        }
+    }
+    return 0;
+}
+
 /*
  * This is the function that uses the table above to take incoming
  * NSEvent keyCodes and translate to the Java virtual key code.
  */
 static void
-NsCharToJavaVirtualKeyCode(unichar ch, unichar deadChar,
+NsCharToJavaVirtualKeyCode(unichar ch, BOOL isDeadChar,
                            NSUInteger flags, unsigned short key,
-                           jint *keyCode, jint *keyLocation, BOOL *postsTyped)
+                           jint *keyCode, jint *keyLocation, BOOL *postsTyped, unichar *deadChar)
 {
     static size_t size = sizeof(keyTable) / sizeof(struct _key);
     NSInteger offset;
 
-    if (deadChar) {
+    if (isDeadChar) {
+        unichar testDeadChar = NsGetDeadKeyChar(key);
         const struct CharToVKEntry *map;
         for (map = charToDeadVKTable; map->c != 0; ++map) {
-            if (deadChar == map->c) {
+            if (testDeadChar == map->c) {
                 *keyCode = map->javaKey;
                 *postsTyped = NO;
                 // TODO: use UNKNOWN here?
                 *keyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
+                *deadChar = testDeadChar;
                 return;
             }
         }
@@ -491,25 +540,51 @@
 /*
  * This returns the java modifiers for a key NSEvent.
  */
-static jint
-NsKeyModifiersToJavaModifiers(NSUInteger nsFlags)
+jint NsKeyModifiersToJavaModifiers(NSUInteger nsFlags, BOOL isExtMods)
 {
     jint javaModifiers = 0;
     const struct _nsKeyToJavaModifier* cur;
 
     for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
         if ((cur->nsMask & nsFlags) != 0) {
-            javaModifiers |= cur->javaMask;
+            javaModifiers |= isExtMods? cur->javaExtMask : cur->javaMask;
         }
     }
 
     return javaModifiers;
 }
 
+/*
+ * This returns the NSEvent flags for java key modifiers.
+ */
+NSUInteger JavaModifiersToNsKeyModifiers(jint javaModifiers, BOOL isExtMods)
+{
+    NSUInteger nsFlags = 0;
+    const struct _nsKeyToJavaModifier* cur;
+
+    for (cur = nsKeyToJavaModifierTable; cur->nsMask != 0; ++cur) {
+        jint mask = isExtMods? cur->javaExtMask : cur->javaMask; 
+        if ((mask & javaModifiers) != 0) {
+            nsFlags |= cur->nsMask;
+        }
+    }
+
+    // special case
+    jint mask = isExtMods? java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK : 
+                           java_awt_event_InputEvent_ALT_GRAPH_MASK;
+
+    if ((mask & javaModifiers) != 0) {
+        nsFlags |= NSAlternateKeyMask;      
+    }
+
+    return nsFlags;
+}
+
+
 jint GetJavaMouseModifiers(NSInteger button, NSUInteger modifierFlags)
 {
     // Mousing needs the key modifiers
-    jint modifiers = NsKeyModifiersToJavaModifiers(modifierFlags);
+    jint modifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
 
 
     /*
@@ -590,7 +665,7 @@
 
 JNF_COCOA_ENTER(env);
 
-    jmodifiers = NsKeyModifiersToJavaModifiers(modifierFlags);
+    jmodifiers = NsKeyModifiersToJavaModifiers(modifierFlags, YES);
 
 JNF_COCOA_EXIT(env);
 
@@ -615,20 +690,22 @@
 
     // in  = [testChar, testDeadChar, modifierFlags, keyCode]
     jchar testChar = (jchar)data[0];
-    jchar testDeadChar = (jchar)data[1];
+    BOOL isDeadChar = (data[1] != 0);
     jint modifierFlags = data[2];
     jshort keyCode = (jshort)data[3];
 
     jint jkeyCode = java_awt_event_KeyEvent_VK_UNDEFINED;
     jint jkeyLocation = java_awt_event_KeyEvent_KEY_LOCATION_UNKNOWN;
+    jchar testDeadChar = 0;
 
-    NsCharToJavaVirtualKeyCode((unichar)testChar, (unichar)testDeadChar,
+    NsCharToJavaVirtualKeyCode((unichar)testChar, isDeadChar,
                                (NSUInteger)modifierFlags, (unsigned short)keyCode,
-                               &jkeyCode, &jkeyLocation, &postsTyped);
+                               &jkeyCode, &jkeyLocation, &postsTyped, &testDeadChar);
 
     // out = [jkeyCode, jkeyLocation];
     (*env)->SetIntArrayRegion(env, outData, 0, 1, &jkeyCode);
     (*env)->SetIntArrayRegion(env, outData, 1, 1, &jkeyLocation);
+    (*env)->SetIntArrayRegion(env, outData, 2, 1, (jint *)&testDeadChar);
 
     (*env)->ReleaseIntArrayElements(env, inData, data, 0);
 
@@ -685,12 +762,12 @@
 (JNIEnv *env, jclass cls, char nsChar, jint modifierFlags)
 {
     jchar javaChar = 0;
-    
+
 JNF_COCOA_ENTER(env);
-    
+
     javaChar = NsCharToJavaChar(nsChar, modifierFlags);
 
 JNF_COCOA_EXIT(env);
-    
+
     return javaChar;
 }
--- a/jdk/src/macosx/native/sun/awt/AWTWindow.m	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m	Wed Sep 19 12:41:54 2012 -0700
@@ -178,8 +178,8 @@
         [self.nsWindow setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)];
     }
 
-    if ([self.nsWindow respondsToSelector:@selector(toggleFullScreen:)]) {
-        if (IS(mask, FULLSCREENABLE)) {
+    if (IS(mask, FULLSCREENABLE) && [self.nsWindow respondsToSelector:@selector(toggleFullScreen:)]) {
+        if (IS(bits, FULLSCREENABLE)) {
             [self.nsWindow setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/];
         } else {
             [self.nsWindow setCollectionBehavior:NSWindowCollectionBehaviorDefault];
--- a/jdk/src/macosx/native/sun/awt/CDragSource.m	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/native/sun/awt/CDragSource.m	Wed Sep 19 12:41:54 2012 -0700
@@ -460,7 +460,7 @@
     }
 
     // Convert fModifiers (extModifiers) to NS:
-    NSUInteger modifiers = [DnDUtilities mapJavaExtModifiersToNSKeyModifiers:fModifiers];
+    NSUInteger modifiers = JavaModifiersToNsKeyModifiers(fModifiers, TRUE); 
 
     // Just a dummy value ...
     NSInteger eventNumber = 0;
@@ -658,7 +658,7 @@
     }
 
     // b) drag actions (key modifiers) have changed:
-    jint modifiers = [DnDUtilities currentJavaExtKeyModifiers];
+    jint modifiers = NsKeyModifiersToJavaModifiers([NSEvent modifierFlags], YES);
     if (fDragKeyModifiers != modifiers) {
         NSDragOperation currentOp = [DnDUtilities nsDragOperationForModifiers:[NSEvent modifierFlags]];
         NSDragOperation allowedOp = [DnDUtilities mapJavaDragOperationToNS:fSourceActions] & currentOp;
--- a/jdk/src/macosx/native/sun/awt/CMenuItem.m	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/native/sun/awt/CMenuItem.m	Wed Sep 19 12:41:54 2012 -0700
@@ -70,6 +70,18 @@
     JNIEnv *env = [ThreadUtilities getJNIEnv];
 JNF_COCOA_ENTER(env);
 
+    // If we are called as a result of user pressing a shorcut, do nothing,
+    // because AVTView has already sent corresponding key event to the Java 
+    // layer from performKeyEquivalent
+    NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
+    if ([currEvent type] == NSKeyDown) {
+        NSString *menuKey = [sender keyEquivalent];
+        NSString *eventKey = [currEvent characters];
+        if ([menuKey isEqualToString:eventKey]) {
+            return;
+        }
+    }
+
     if (fIsCheckbox) {
         static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem");
         static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V");
@@ -83,14 +95,8 @@
         static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
         static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
 
-        NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
         NSUInteger modifiers = [currEvent modifierFlags];
-        jint javaModifiers = 0;
-
-        if ((modifiers & NSCommandKeyMask) != 0)   javaModifiers |= java_awt_Event_META_MASK;
-        if ((modifiers & NSShiftKeyMask) != 0)     javaModifiers |= java_awt_Event_SHIFT_MASK;
-        if ((modifiers & NSControlKeyMask) != 0)   javaModifiers |= java_awt_Event_CTRL_MASK;
-        if ((modifiers & NSAlternateKeyMask) != 0) javaModifiers |= java_awt_Event_ALT_MASK;
+        jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
 
         JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
     }
@@ -117,10 +123,7 @@
             modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK;
         }
 
-        if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0) modifierMask |= NSShiftKeyMask;
-        if ((modifiers & java_awt_event_KeyEvent_CTRL_MASK) != 0)  modifierMask |= NSControlKeyMask;
-        if ((modifiers & java_awt_event_KeyEvent_ALT_MASK) != 0)   modifierMask |= NSAlternateKeyMask;
-        if ((modifiers & java_awt_event_KeyEvent_META_MASK) != 0)  modifierMask |= NSCommandKeyMask;
+        modifierMask = JavaModifiersToNsKeyModifiers(modifiers, NO);
     }
 
     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
--- a/jdk/src/macosx/native/sun/awt/CTextPipe.m	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/native/sun/awt/CTextPipe.m	Wed Sep 19 12:41:54 2012 -0700
@@ -239,9 +239,22 @@
     CGContextSetTextMatrix(cgRef, CGAffineTransformIdentity); // resets the damage from CoreText
 
     NSString *string = [NSString stringWithCharacters:chars length:length];
+    /*
+       The calls below were used previously but for unknown reason did not 
+       render using the right font (see bug 7183516) when attribString is not 
+       initialized with font dictionary attributes.  It seems that "options" 
+       in CTTypesetterCreateWithAttributedStringAndOptions which contains the 
+       font dictionary is ignored.
+
     NSAttributedString *attribString = [[NSAttributedString alloc] initWithString:string];
 
     CTTypesetterRef typeSetterRef = CTTypesetterCreateWithAttributedStringAndOptions((CFAttributedStringRef) attribString, (CFDictionaryRef) ctsDictionaryFor(nsFont, JRSFontStyleUsesFractionalMetrics(strike->fStyle)));
+    */
+    NSAttributedString *attribString = [[NSAttributedString alloc]
+        initWithString:string
+        attributes:ctsDictionaryFor(nsFont, JRSFontStyleUsesFractionalMetrics(strike->fStyle))];
+    
+    CTTypesetterRef typeSetterRef = CTTypesetterCreateWithAttributedString((CFAttributedStringRef) attribString);
 
     CFRange range = {0, length};
     CTLineRef lineRef = CTTypesetterCreateLine(typeSetterRef, range);
--- a/jdk/src/macosx/native/sun/awt/DnDUtilities.h	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/native/sun/awt/DnDUtilities.h	Wed Sep 19 12:41:54 2012 -0700
@@ -42,7 +42,6 @@
 + (jint)narrowJavaDropActions:(jint)actions;
 
 // Mouse and key modifiers mapping:
-+ (NSUInteger)mapJavaExtModifiersToNSKeyModifiers:(jint)modifiers;
 + (NSUInteger)mapJavaExtModifiersToNSMouseDownButtons:(jint)modifiers;
 + (NSUInteger)mapJavaExtModifiersToNSMouseUpButtons:(jint)modifiers;
 
@@ -50,9 +49,6 @@
 + (jint)extractJavaExtKeyModifiersFromJavaExtModifiers:(jint)modifiers;
 + (jint)extractJavaExtMouseModifiersFromJavaExtModifiers:(jint)modifiers;
 
-// Get the current keyboard modifier keys as java modifiers (for operationChanged)
-+ (jint)currentJavaExtKeyModifiers;
-
 // Getting the state of the current Drag
 + (NSDragOperation)nsDragOperationForModifiers:(NSUInteger)modifiers;
 + (jint) javaKeyModifiersForNSDragOperation:(NSDragOperation)dragOp;
--- a/jdk/src/macosx/native/sun/awt/DnDUtilities.m	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/macosx/native/sun/awt/DnDUtilities.m	Wed Sep 19 12:41:54 2012 -0700
@@ -161,28 +161,6 @@
 }
 
 // Mouse and key modifiers mapping:
-+ (NSUInteger)mapJavaExtModifiersToNSKeyModifiers:(jint)modifiers
-{
-    NSUInteger result = 0;
-
-    if ((modifiers & java_awt_event_InputEvent_SHIFT_DOWN_MASK) != 0)
-        result |= NSShiftKeyMask;
-
-    if ((modifiers & java_awt_event_InputEvent_CTRL_DOWN_MASK) != 0)
-        result |= NSControlKeyMask;
-
-    if ((modifiers & java_awt_event_InputEvent_META_DOWN_MASK) != 0)
-        result |= NSCommandKeyMask;
-
-    if ((modifiers & java_awt_event_InputEvent_ALT_DOWN_MASK) != 0)
-        result |= NSAlternateKeyMask;
-
-    if ((modifiers & java_awt_event_InputEvent_ALT_GRAPH_DOWN_MASK) != 0)
-        result |= NSAlternateKeyMask;
-
-    return result;
-}
-
 + (NSUInteger)mapJavaExtModifiersToNSMouseDownButtons:(jint)modifiers
 {
     NSUInteger result = NSLeftMouseDown;
@@ -245,32 +223,6 @@
     return modifiers & mask;
 }
 
-
-+ (jint)currentJavaExtKeyModifiers
-{
-    NSUInteger modifiers = [NSEvent modifierFlags];
-    jint jmodifiers = 0;
-
-    if(modifiers & NSShiftKeyMask) {
-        jmodifiers |= java_awt_event_InputEvent_SHIFT_DOWN_MASK;
-    }
-
-    if(modifiers & NSControlKeyMask) {
-        jmodifiers |= java_awt_event_InputEvent_CTRL_DOWN_MASK;
-    }
-
-    if(modifiers & NSAlternateKeyMask) {
-        jmodifiers |= java_awt_event_InputEvent_ALT_DOWN_MASK;
-    }
-
-    if(modifiers & NSCommandKeyMask) {
-        jmodifiers |= java_awt_event_InputEvent_META_DOWN_MASK;
-    }
-
-    return jmodifiers;
-}
-
-
 + (NSDragOperation) nsDragOperationForModifiers:(NSUInteger)modifiers {
 
     // Java first
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java	Wed Sep 19 12:41:54 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -644,6 +644,9 @@
                    "released SPACE", "released"
                  }),
 
+            "Caret.width",
+                  new DesktopProperty("win.caret.width", null),
+
             "CheckBox.font", ControlFont,
             "CheckBox.interiorBackground", WindowBackgroundColor,
             "CheckBox.background", ControlBackgroundColor,
--- a/jdk/src/share/classes/java/awt/EventQueue.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/share/classes/java/awt/EventQueue.java	Wed Sep 19 12:41:54 2012 -0700
@@ -1047,6 +1047,10 @@
 
     final boolean detachDispatchThread(EventDispatchThread edt, boolean forceDetach) {
         /*
+         * Minimize discard possibility for non-posted events
+         */
+        SunToolkit.flushPendingEvents();
+        /*
          * This synchronized block is to secure that the event dispatch
          * thread won't die in the middle of posting a new event to the
          * associated event queue. It is important because we notify
@@ -1060,11 +1064,8 @@
                 /*
                  * Don't detach the thread if any events are pending. Not
                  * sure if it's a possible scenario, though.
-                 *
-                 * Fix for 4648733. Check both the associated java event
-                 * queue and the PostEventQueue.
                  */
-                if (!forceDetach && (peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) {
+                if (!forceDetach && (peekEvent() != null)) {
                     return false;
                 }
                 dispatchThread = null;
--- a/jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java	Wed Sep 19 12:41:54 2012 -0700
@@ -495,6 +495,16 @@
         indexedReadMethodName = old.indexedReadMethodName;
     }
 
+    void updateGenericsFor(Class<?> type) {
+        super.updateGenericsFor(type);
+        try {
+            setIndexedPropertyType(findIndexedPropertyType(getIndexedReadMethod0(), getIndexedWriteMethod0()));
+        }
+        catch (IntrospectionException exception) {
+            setIndexedPropertyType(null);
+        }
+    }
+
     /**
      * Returns a hash code value for the object.
      * See {@link java.lang.Object#hashCode} for a complete description.
--- a/jdk/src/share/classes/java/beans/Introspector.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/share/classes/java/beans/Introspector.java	Wed Sep 19 12:41:54 2012 -0700
@@ -574,26 +574,25 @@
             // replace existing property descriptor
             // only if we have types to resolve
             // in the context of this.beanClass
-            try {
-                String name = pd.getName();
-                Method read = pd.getReadMethod();
-                Method write = pd.getWriteMethod();
-                boolean cls = true;
-                if (read != null) cls = cls && read.getGenericReturnType() instanceof Class;
-                if (write != null) cls = cls && write.getGenericParameterTypes()[0] instanceof Class;
-                if (pd instanceof IndexedPropertyDescriptor) {
-                    IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor)pd;
-                    Method readI = ipd.getIndexedReadMethod();
-                    Method writeI = ipd.getIndexedWriteMethod();
-                    if (readI != null) cls = cls && readI.getGenericReturnType() instanceof Class;
-                    if (writeI != null) cls = cls && writeI.getGenericParameterTypes()[1] instanceof Class;
-                    if (!cls) {
-                        pd = new IndexedPropertyDescriptor(this.beanClass, name, read, write, readI, writeI);
-                    }
-                } else if (!cls) {
-                    pd = new PropertyDescriptor(this.beanClass, name, read, write);
+            Method read = pd.getReadMethod();
+            Method write = pd.getWriteMethod();
+            boolean cls = true;
+            if (read != null) cls = cls && read.getGenericReturnType() instanceof Class;
+            if (write != null) cls = cls && write.getGenericParameterTypes()[0] instanceof Class;
+            if (pd instanceof IndexedPropertyDescriptor) {
+                IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
+                Method readI = ipd.getIndexedReadMethod();
+                Method writeI = ipd.getIndexedWriteMethod();
+                if (readI != null) cls = cls && readI.getGenericReturnType() instanceof Class;
+                if (writeI != null) cls = cls && writeI.getGenericParameterTypes()[1] instanceof Class;
+                if (!cls) {
+                    pd = new IndexedPropertyDescriptor(ipd);
+                    pd.updateGenericsFor(this.beanClass);
                 }
-            } catch ( IntrospectionException e ) {
+            }
+            else if (!cls) {
+                pd = new PropertyDescriptor(pd);
+                pd.updateGenericsFor(this.beanClass);
             }
         }
         list.add(pd);
--- a/jdk/src/share/classes/java/beans/PropertyDescriptor.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/share/classes/java/beans/PropertyDescriptor.java	Wed Sep 19 12:41:54 2012 -0700
@@ -632,6 +632,16 @@
         constrained = old.constrained;
     }
 
+    void updateGenericsFor(Class<?> type) {
+        setClass0(type);
+        try {
+            setPropertyType(findPropertyType(getReadMethod0(), getWriteMethod0()));
+        }
+        catch (IntrospectionException exception) {
+            setPropertyType(null);
+        }
+    }
+
     /**
      * Returns the property type that corresponds to the read and write method.
      * The type precedence is given to the readMethod.
--- a/jdk/src/share/classes/javax/swing/text/DefaultCaret.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/share/classes/javax/swing/text/DefaultCaret.java	Wed Sep 19 12:41:54 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -1503,9 +1503,14 @@
 
         if (caretWidth > -1) {
             return caretWidth;
+        } else {
+            Object property = UIManager.get("Caret.width");
+            if (property instanceof Integer) {
+                return ((Integer) property).intValue();
+            } else {
+                return 1;
+            }
         }
-
-        return 1;
     }
 
     // --- serialization ---------------------------------------------
--- a/jdk/src/share/classes/sun/awt/SunToolkit.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java	Wed Sep 19 12:41:54 2012 -0700
@@ -506,40 +506,25 @@
         postEvent(targetToAppContext(e.getSource()), pe);
     }
 
-    protected static final Lock flushLock = new ReentrantLock();
-    private static boolean isFlushingPendingEvents = false;
-
     /*
      * Flush any pending events which haven't been posted to the AWT
      * EventQueue yet.
      */
     public static void flushPendingEvents()  {
-        flushLock.lock();
-        try {
-            // Don't call flushPendingEvents() recursively
-            if (!isFlushingPendingEvents) {
-                isFlushingPendingEvents = true;
-                AppContext appContext = AppContext.getAppContext();
-                PostEventQueue postEventQueue =
-                    (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
-                if (postEventQueue != null) {
-                    postEventQueue.flush();
-                }
-            }
-        } finally {
-            isFlushingPendingEvents = false;
-            flushLock.unlock();
-        }
+        AppContext appContext = AppContext.getAppContext();
+        flushPendingEvents(appContext);
     }
 
-    public static boolean isPostEventQueueEmpty()  {
-        AppContext appContext = AppContext.getAppContext();
+    /*
+     * Flush the PostEventQueue for the right AppContext.
+     * The default flushPendingEvents only flushes the thread-local context,
+     * which is not always correct, c.f. 3746956
+     */
+    public static void flushPendingEvents(AppContext appContext) {
         PostEventQueue postEventQueue =
-            (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
+                (PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
         if (postEventQueue != null) {
-            return postEventQueue.noEvents();
-        } else {
-            return true;
+            postEventQueue.flush();
         }
     }
 
@@ -2045,17 +2030,12 @@
     private EventQueueItem queueTail = null;
     private final EventQueue eventQueue;
 
-    // For the case when queue is cleared but events are not posted
-    private volatile boolean isFlushing = false;
+    private Thread flushThread = null;
 
     PostEventQueue(EventQueue eq) {
         eventQueue = eq;
     }
 
-    public synchronized boolean noEvents() {
-        return queueHead == null && !isFlushing;
-    }
-
     /*
      * Continually post pending AWTEvents to the Java EventQueue. The method
      * is synchronized to ensure the flush is completed before a new event
@@ -2066,20 +2046,48 @@
      * potentially lead to deadlock
      */
     public void flush() {
-        EventQueueItem tempQueue;
-        synchronized (this) {
-            tempQueue = queueHead;
-            queueHead = queueTail = null;
-            isFlushing = true;
-        }
+
+        Thread newThread = Thread.currentThread();
+
         try {
-            while (tempQueue != null) {
-                eventQueue.postEvent(tempQueue.event);
-                tempQueue = tempQueue.next;
+            EventQueueItem tempQueue;
+            synchronized (this) {
+                // Avoid method recursion
+                if (newThread == flushThread) {
+                    return;
+                }
+                // Wait for other threads' flushing
+                while (flushThread != null) {
+                    wait();
+                }
+                // Skip everything if queue is empty
+                if (queueHead == null) {
+                    return;
+                }
+                // Remember flushing thread
+                flushThread = newThread;
+
+                tempQueue = queueHead;
+                queueHead = queueTail = null;
+            }
+            try {
+                while (tempQueue != null) {
+                    eventQueue.postEvent(tempQueue.event);
+                    tempQueue = tempQueue.next;
+                }
+            }
+            finally {
+                // Only the flushing thread can get here
+                synchronized (this) {
+                    // Forget flushing thread, inform other pending threads
+                    flushThread = null;
+                    notifyAll();
+                }
             }
         }
-        finally {
-            isFlushing = false;
+        catch (InterruptedException e) {
+            // Couldn't allow exception go up, so at least recover the flag
+            newThread.interrupt();
         }
     }
 
--- a/jdk/src/share/classes/sun/awt/image/VolatileSurfaceManager.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/share/classes/sun/awt/image/VolatileSurfaceManager.java	Wed Sep 19 12:41:54 2012 -0700
@@ -333,11 +333,12 @@
             // using a SurfaceData that was created in a different
             // display mode.
             sdBackup = null;
-            sdCurrent = getBackupSurface();
             // Now, invalidate the old hardware-based SurfaceData
+            // Note that getBackupSurface may set sdAccel to null so we have to invalidate it before
             SurfaceData oldData = sdAccel;
             sdAccel = null;
             oldData.invalidate();
+            sdCurrent = getBackupSurface();
         }
         // Update graphicsConfig for the vImg in case it changed due to
         // this display change event
--- a/jdk/src/windows/classes/sun/java2d/ScreenUpdateManager.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/windows/classes/sun/java2d/ScreenUpdateManager.java	Wed Sep 19 12:41:54 2012 -0700
@@ -110,6 +110,11 @@
     public SurfaceData getReplacementScreenSurface(WComponentPeer peer,
                                                    SurfaceData oldsd)
     {
+        SurfaceData surfaceData = peer.getSurfaceData();
+        if (surfaceData.isValid()) {
+            return surfaceData;
+        }
+        peer.replaceSurfaceData();
         return peer.getSurfaceData();
     }
 
--- a/jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp	Wed Sep 19 12:41:54 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -70,6 +70,7 @@
     GetNonClientParameters();
     GetIconParameters();
     GetColorParameters();
+    GetCaretParameters();
     GetOtherParameters();
     GetSoundEvents();
     GetSystemProperties();
@@ -636,6 +637,10 @@
     SetSoundProperty(TEXT("win.sound.start"), TEXT("SystemStart"));
 }
 
+void AwtDesktopProperties::GetCaretParameters() {
+    SetIntegerProperty(TEXT("win.caret.width"), GetIntegerParameter(SPI_GETCARETWIDTH));
+}
+
 BOOL AwtDesktopProperties::GetBooleanParameter(UINT spi) {
     BOOL        flag;
     SystemParametersInfo(spi, 0, &flag, 0);
--- a/jdk/src/windows/native/sun/windows/awt_DesktopProperties.h	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_DesktopProperties.h	Wed Sep 19 12:41:54 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -64,6 +64,7 @@
         void GetColorParameters();
         void GetOtherParameters();
         void GetSoundEvents();
+        void GetCaretParameters();
 
         static BOOL GetBooleanParameter(UINT spi);
         static UINT GetIntegerParameter(UINT spi);
--- a/jdk/src/windows/native/sun/windows/awt_TextField.cpp	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/src/windows/native/sun/windows/awt_TextField.cpp	Wed Sep 19 12:41:54 2012 -0700
@@ -75,6 +75,7 @@
 AwtTextField::HandleEvent(MSG *msg, BOOL synthetic)
 {
     MsgRouting returnVal;
+    BOOL systemBeeperEnabled = FALSE;
     /*
      * RichEdit 1.0 control starts internal message loop if the
      * left mouse button is pressed while the cursor is not over
@@ -217,7 +218,34 @@
         }
         delete msg;
         return mrConsume;
+    } else if (msg->message == WM_KEYDOWN) {
+        UINT virtualKey = (UINT) msg->wParam;
+
+        switch(virtualKey){
+          case VK_RETURN:
+          case VK_UP:
+          case VK_DOWN:
+          case VK_LEFT:
+          case VK_RIGHT:
+          case VK_DELETE:
+          case VK_BACK:
+              SystemParametersInfo(SPI_GETBEEP, 0, &systemBeeperEnabled, 0);
+              if(systemBeeperEnabled){
+                  // disable system beeper for the RICHEDIT control to be compatible
+                  // with the EDIT control behaviour
+                  SystemParametersInfo(SPI_SETBEEP, 0, NULL, 0);
+              }
+              break;
+          }
+    } else if (msg->message == WM_SETTINGCHANGE) {
+        if (msg->wParam == SPI_SETBEEP) {
+            SystemParametersInfo(SPI_GETBEEP, 0, &systemBeeperEnabled, 0);
+            if(systemBeeperEnabled){
+                SystemParametersInfo(SPI_SETBEEP, 1, NULL, 0);
+            }
+        }
     }
+
     /*
      * Store the 'synthetic' parameter so that the WM_PASTE security check
      * happens only for synthetic events.
@@ -226,6 +254,10 @@
     returnVal = AwtComponent::HandleEvent(msg, synthetic);
     m_synthetic = FALSE;
 
+    if(systemBeeperEnabled){
+        SystemParametersInfo(SPI_SETBEEP, 1, NULL, 0);
+    }
+
     return returnVal;
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/EventQueue/PostEventOrderingTest/PostEventOrderingTest.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+/**
+ * @test PostEventOrderingTest.java
+ * @bug 4171596 6699589
+ * @summary Checks that the posting of events between the PostEventQueue
+ * @summary and the EventQueue maintains proper ordering.
+ * @run main PostEventOrderingTest
+ * @author fredx
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import sun.awt.AppContext;
+import sun.awt.SunToolkit;
+
+public class PostEventOrderingTest {
+    static boolean testPassed = true;
+
+    public static void main(String[] args) throws Throwable {
+        EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue();
+        for (int i = 0; i < 100; i++) {
+            for (int j = 0; j < 100; j++) {
+                q.postEvent(new PostActionEvent());
+                for (int k = 0; k < 10; k++) {
+                    SunToolkit.postEvent(AppContext.getAppContext(), new PostActionEvent());
+                }
+            }
+            for (int k = 0; k < 100; k++) {
+                SunToolkit.postEvent(AppContext.getAppContext(), new PostActionEvent());
+            }
+        }
+
+        for (;;) {
+            Thread.currentThread().sleep(100);
+            if (q.peekEvent() == null) {
+                Thread.currentThread().sleep(100);
+                if (q.peekEvent() == null)
+                    break;
+            }
+        }
+
+        if (!testPassed) {
+            throw new Exception("PostEventOrderingTest FAILED -- events dispatched out of order.");
+        } else {
+            System.out.println("PostEventOrderingTest passed!");
+        }
+    }
+}
+
+class PostActionEvent extends ActionEvent implements ActiveEvent {
+    static int counter = 0;
+    static int mostRecent = -1;
+
+    int myval;
+
+    public PostActionEvent() {
+        super("", ACTION_PERFORMED, "" + counter);
+        myval = counter++;
+    }
+
+    public void dispatch() {
+        //System.out.println("myval = "+myval+", mostRecent = "+mostRecent+", diff = "+(myval-mostRecent)+".");
+        if ((myval - mostRecent) != 1)
+            PostEventOrderingTest.testPassed = false;
+        mostRecent = myval;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/JAWT/JAWT.sh	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,173 @@
+#!/bin/sh
+
+# 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.
+
+# @test JAWT.sh
+# @bug 7190587
+# @summary Tests Java AWT native interface library
+# @author kshefov
+# @run shell JAWT.sh
+
+# NB: To run on Windows with MKS and Visual Studio compiler
+# add the following options to jtreg: -e INCLUDE="%INCLUDE%;." -e LIB="%LIB%;."
+
+if [ "${TESTSRC}" = "" ]
+then TESTSRC=.
+fi
+
+if [ "${TESTJAVA}" = "" ]
+then
+  PARENT=`dirname \`which java\``
+  TESTJAVA=`dirname ${PARENT}`
+  echo "TESTJAVA not set, selecting " ${TESTJAVA}
+  echo "If this is incorrect, try setting the variable manually."
+fi
+
+# set platform-dependent variables
+OS=`uname -s`
+case "$OS" in
+  Linux )
+    NULL=/dev/null
+    PS=":"
+    FS="/"
+    ${TESTJAVA}${FS}bin${FS}java -version 2>&1 | grep '64-Bit' > $NULL
+    if [ $? -eq '0' ]
+    then
+        ARCH="amd64"
+    else
+        ARCH="i386"
+    fi
+    SYST="linux"
+    MAKEFILE="Makefile.unix"
+    CC="gcc"
+	MAKE="make"
+	LD_LIBRARY_PATH="."
+    ;;
+  SunOS )
+    NULL=/dev/null
+    PS=":"
+    FS="/"
+    if [ `uname -p | grep -c 'sparc'` -gt '0' ]
+    then
+        ARCH="sparc"
+    else
+        ARCH="i386"
+    fi
+    SYST="solaris"
+    MAKEFILE="Makefile.unix"
+    CC="gcc"
+	MAKE="make"
+	LD_LIBRARY_PATH="."
+    ;;
+  Windows* )
+    NULL=null
+    PS=";"
+    FS="\\"
+    MAKEFILE="Makefile.win"
+    CC="cl"
+	MAKE="nmake"
+	${TESTJAVA}${FS}bin${FS}java -d64 -version 2>&1 | grep '64-Bit' > $NULL
+    if [ "$?" -eq '0' ]
+    then
+        ARCH="amd64"
+    else
+        ARCH="i386"
+    fi
+	SYST="windows"
+    ;;
+  CYGWIN* )
+    NULL=/dev/null
+    PS=":"
+    FS="/"
+    MAKEFILE="Makefile.cygwin"
+    CC="gcc"
+	${TESTJAVA}${FS}bin${FS}java -d64 -version 2>&1 | grep '64-Bit' > $NULL
+    if [ "$?" -eq '0' ]
+    then
+        ARCH="amd64"
+    else
+        ARCH="i386"
+    fi
+	SYST="cygwin"	
+	MAKE="make"
+    ;;
+  Darwin )
+    echo "Test passed. This test is not for MacOS."
+    exit 0;
+    ;;
+  * )
+    echo "Unrecognized system!"
+    exit 1;
+    ;;
+esac
+
+# Skip unsupported platforms
+case `uname -m` in
+    arm* | ppc* )
+      echo "Test passed. Not supported on current architecture."
+      exit 0
+      ;;
+esac
+
+echo "OS-ARCH is" ${SYST}-${ARCH}
+${TESTJAVA}${FS}jre${FS}bin${FS}java -fullversion 2>&1
+
+which ${MAKE} >${NULL} 2>&1
+if [ "$?" -ne '0' ]
+then
+    echo "No make found. Test passed."
+    exit 0
+fi
+
+which ${CC} >${NULL} 2>&1
+if [ "$?" -ne '0' ]
+then
+    echo "No C compiler found. Test passed."
+    exit 0
+fi
+case "$OS" in
+    SunOS )
+      ${CC} -v >${NULL} 2>&1
+      if [ "$?" -ne '0' ]
+      then
+          echo "No C compiler found. Test passed."
+          exit 0
+      fi
+esac
+
+cp ${TESTSRC}${FS}${MAKEFILE} .
+
+JAVA=${TESTJAVA}${FS}jre${FS}bin${FS}java
+JAVAC=${TESTJAVA}${FS}bin${FS}javac
+JAVAH=${TESTJAVA}${FS}bin${FS}javah
+
+export CC SYST ARCH LD_LIBRARY_PATH
+
+${JAVAC} -d . ${TESTSRC}${FS}MyCanvas.java
+${JAVAH} -jni -classpath . -d . MyCanvas
+${MAKE} -f ${MAKEFILE}
+${JAVA} -classpath . MyCanvas
+
+exit $?
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/JAWT/Makefile.cygwin	Wed Sep 19 12:41:54 2012 -0700
@@ -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.  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.
+
+CFLAGS =	
+OBJS =		myfile.o
+HEADERS =	MyCanvas.h
+CLASSES =	MyCanvas.class
+
+JAVA =		$(TESTJAVA)/bin/java -classpath .
+JAVAC =		$(TESTJAVA)/bin/javac
+JAVAH =		$(TESTJAVA)/bin/javah
+DEL =		rm -rf
+LINK =		$(CC)
+
+INCLUDES =	-I $(TESTJAVA)/include/win32 -I $(TESTJAVA)/include -I .
+
+LIBS =		$(TESTJAVA)/lib/jawt.lib -lgdi32
+
+all:		$(CLASSES) mylib.dll
+
+mylib.dll: $(HEADERS) $(OBJS) 
+	$(LINK) -shared -o mylib.dll $(OBJS) $(LIBS) 
+
+myfile.o:
+	$(CC) $(CFLAGS)  $(INCLUDES) -c $(TESTSRC)/myfile.cpp
+
+clean:
+	$(DEL) mylib.* *.h *.class *.o
+ 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/JAWT/Makefile.unix	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,48 @@
+# 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.
+
+CFLAGS =	-fPIC -O
+OBJS =		myfile.o
+HEADERS =	MyCanvas.h
+CLASSES =	MyCanvas.class
+
+ENV =		/usr/bin/env
+JAVA =		$(TESTJAVA)/bin/java -classpath .
+JAVAC =		$(TESTJAVA)/bin/javac
+JAVAH =		$(TESTJAVA)/bin/javah
+LINK =		ld
+
+J_INC =		$(TESTJAVA)/include
+INCLUDES =	-I$(J_INC) -I$(J_INC)/$(SYST) -I.
+LIBS =		-L$(TESTJAVA)/jre/lib/$(ARCH) -ljawt -lX11
+
+all:		$(CLASSES) libmylib.so
+
+libmylib.so: $(HEADERS) $(OBJS) 
+	$(LINK) -G -o libmylib.so $(OBJS) $(LIBS)
+
+myfile.o:	$(TESTSRC)/myfile.c
+	$(CC)  $(CFLAGS) $(INCLUDES) -c $(TESTSRC)/myfile.c
+
+clean:
+	rm -rf libmylib.so $(HEADERS) $(CLASSES) $(OBJS)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/JAWT/Makefile.win	Wed Sep 19 12:41:54 2012 -0700
@@ -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.  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.
+
+CFLAGS =	-nologo
+OBJS =		myfile.obj
+HEADERS =	MyCanvas.h
+CLASSES =	MyCanvas.class
+
+DEL =		del /Q
+LINK =		link
+
+INCLUDES =	-I$(TESTJAVA)\include\win32 -I$(TESTJAVA)\include
+
+LIBS =		gdi32.lib user32.lib $(TESTJAVA)\lib\jawt.lib
+
+all:		$(CLASSES) mylib.dll
+
+mylib.dll: $(HEADERS) $(OBJS) 
+	$(LINK) -nologo -dll -out:mylib.dll $(OBJS) $(LIBS)
+
+myfile.obj: $(TESTSRC)\myfile.cpp
+	$(CC) $(CFLAGS) $(INCLUDES) -c $(TESTSRC)\myfile.cpp
+
+clean:
+	$(DEL) mylib.* 
+	$(DEL) $(HEADERS) $(CLASSES)
+	$(DEL) *.obj
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/JAWT/MyCanvas.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,72 @@
+/**
+ * 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.
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class MyCanvas extends Canvas {
+
+    static {
+        try {
+            System.loadLibrary("mylib");
+        } catch (Throwable t) {
+            System.out.println("Test failed!!");
+            t.printStackTrace();
+            System.exit(1);
+        }
+    }
+
+    public native void paint(Graphics g);
+
+    public static void main(String[] args) {
+        try {
+            Robot robot = new Robot();
+            Frame f = new Frame();
+            f.setBounds(0, 0, 100, 100);
+            f.add(new MyCanvas());
+            f.addWindowListener(new WindowAdapter() {
+                public void windowClosing(WindowEvent ev) {
+                    System.exit(0);
+                }
+            });
+            f.setVisible(true);
+            robot.delay(5000);
+            Color col1 = new Color(0, 0, 0);
+            Color col2 = robot.getPixelColor(f.getX()+50, f.getY()+50);
+            if (col1.equals(col2)) {
+                System.out.println("Test passed!");
+            } else {
+                throw new RuntimeException("Color of JAWT canvas is wrong or " +
+                        "it was not rendered. " + "Check that other windows " +
+                        "do not block the test frame.");
+            }
+            System.exit(0);
+        } catch (Throwable t) {
+            System.out.println("Test failed!");
+            t.printStackTrace();
+            System.exit(1);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/JAWT/myfile.c	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+
+#include "MyCanvas.h"
+#include "jawt_md.h"
+
+/*
+ * Class:     MyCanvas
+ * Method:    paint
+ * Signature: (Ljava/awt/Graphics;)V
+ */
+JNIEXPORT void JNICALL Java_MyCanvas_paint
+(JNIEnv* env, jobject canvas, jobject graphics)
+{
+    JAWT awt;
+    JAWT_DrawingSurface* ds;
+    JAWT_DrawingSurfaceInfo* dsi;
+    JAWT_X11DrawingSurfaceInfo* dsi_x11;
+    jboolean result;
+    jint lock;
+    GC gc;
+    jobject ref;
+
+    /* Get the AWT */
+    awt.version = JAWT_VERSION_1_4;
+    if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
+        printf("AWT Not found\n");
+        return;
+    }
+
+    /* Lock the AWT */
+    awt.Lock(env);
+
+    /* Unlock the AWT */
+    awt.Unlock(env);
+
+    /* Get the drawing surface */
+    ds = awt.GetDrawingSurface(env, canvas);
+    if (ds == NULL) {
+        printf("NULL drawing surface\n");
+        return;
+    }
+
+    /* Lock the drawing surface */
+    lock = ds->Lock(ds);
+    printf("Lock value %d\n", (int)lock);
+    if((lock & JAWT_LOCK_ERROR) != 0) {
+        printf("Error locking surface\n");
+        awt.FreeDrawingSurface(ds);
+        return;
+    }
+
+    /* Get the drawing surface info */
+    dsi = ds->GetDrawingSurfaceInfo(ds);
+    if (dsi == NULL) {
+        printf("Error getting surface info\n");
+        ds->Unlock(ds);
+        awt.FreeDrawingSurface(ds);
+        return;
+    }
+
+    /* Get the platform-specific drawing info */
+    dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
+
+    /* Now paint */
+    gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
+    XSetForeground(dsi_x11->display, gc, 0);
+    XFillRectangle(dsi_x11->display, dsi_x11->drawable, gc,
+                   5, 5, 90, 90);
+    XFreeGC(dsi_x11->display, gc);
+    ref = awt.GetComponent(env, (void*)(dsi_x11->drawable));
+    if (!(*env)->IsSameObject(env, ref, canvas)) {
+        printf("Error! Different objects!\n");
+    }
+
+    /* Free the drawing surface info */
+    ds->FreeDrawingSurfaceInfo(dsi);
+
+    /* Unlock the drawing surface */
+    ds->Unlock(ds);
+
+    /* Free the drawing surface */
+    awt.FreeDrawingSurface(ds);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/JAWT/myfile.cpp	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+#include <windows.h>
+#include "MyCanvas.h"
+#include "jawt_md.h"
+
+/*
+ * Class:     MyCanvas
+ * Method:    paint
+ * Signature: (Ljava/awt/Graphics;)V
+ */
+
+extern "C" {
+
+JNIEXPORT void JNICALL Java_MyCanvas_paint
+(JNIEnv* env, jobject canvas, jobject graphics)
+{
+    /* Get the AWT */
+    JAWT awt;
+    awt.version = JAWT_VERSION_1_4;
+    if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
+        printf("AWT Not found\n");
+        return;
+    }
+
+    /* Lock the AWT */
+    awt.Lock(env);
+
+    /* Unlock the AWT */
+    awt.Unlock(env);
+
+    /* Get the drawing surface */
+    JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, canvas);
+    if (ds == NULL) {
+        printf("NULL drawing surface\n");
+        return;
+    }
+
+    /* Lock the drawing surface */
+    jint lock = ds->Lock(ds);
+    printf("Lock value %d\n", (int)lock);
+    if((lock & JAWT_LOCK_ERROR) != 0) {
+        printf("Error locking surface\n");
+        return;
+    }
+
+    /* Get the drawing surface info */
+    JAWT_DrawingSurfaceInfo* dsi = ds->GetDrawingSurfaceInfo(ds);
+    if (dsi == NULL) {
+        printf("Error getting surface info\n");
+        ds->Unlock(ds);
+        return;
+    }
+
+    /* Get the platform-specific drawing info */
+    JAWT_Win32DrawingSurfaceInfo* dsi_win =
+        (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
+
+    /* Now paint */
+    PAINTSTRUCT ps;
+    /* Do not use the HDC returned from BeginPaint()!! */
+    ::BeginPaint(dsi_win->hwnd, &ps);
+    HBRUSH hbrush = (HBRUSH)::GetStockObject(BLACK_BRUSH);
+    RECT rect;
+    rect.left = 5;
+    rect.top = 5;
+    rect.right = 95;
+    rect.bottom = 95;
+    ::FillRect(dsi_win->hdc, &rect, hbrush);
+    ::EndPaint(dsi_win->hwnd, &ps);
+
+    jobject ref = awt.GetComponent(env, (void*)(dsi_win->hwnd));
+    if (!env->IsSameObject(ref, canvas)) {
+        printf("Error! Different objects!\n");
+    }
+
+    /* Free the drawing surface info */
+    ds->FreeDrawingSurfaceInfo(dsi);
+
+    /* Unlock the drawing surface */
+    ds->Unlock(ds);
+
+    /* Free the drawing surface */
+    awt.FreeDrawingSurface(ds);
+}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/event/KeyEvent/DeadKey/deadKeyMacOSX.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,138 @@
+/*
+ * 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 7196547
+ * @summary Dead Key implementation for KeyEvent on Mac OS X
+ * @author alexandr.scherbatiy area=awt.event
+ * @run main deadKeyMacOSX
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.event.KeyEvent;
+import sun.awt.OSInfo;
+import sun.awt.SunToolkit;
+
+public class deadKeyMacOSX {
+
+    private static SunToolkit toolkit;
+    private static volatile int state = 0;
+
+    public static void main(String[] args) throws Exception {
+
+        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
+            return;
+        }
+
+        toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+        Robot robot = new Robot();
+        robot.setAutoDelay(50);
+
+        createAndShowGUI();
+
+        // Pressed keys: Alt + E + A
+        // Results:  ALT + VK_DEAD_ACUTE + a with accute accent
+        robot.keyPress(KeyEvent.VK_ALT);
+        robot.keyPress(KeyEvent.VK_E);
+        robot.keyRelease(KeyEvent.VK_E);
+        robot.keyRelease(KeyEvent.VK_ALT);
+
+        robot.keyPress(KeyEvent.VK_A);
+        robot.keyRelease(KeyEvent.VK_A);
+
+        if (state != 3) {
+            throw new RuntimeException("Wrong number of key events.");
+        }
+    }
+
+    static void createAndShowGUI() {
+        Frame frame = new Frame();
+        frame.setSize(300, 300);
+        Panel panel = new Panel();
+        panel.addKeyListener(new DeadKeyListener());
+        frame.add(panel);
+        frame.setVisible(true);
+        toolkit.realSync();
+
+        panel.requestFocusInWindow();
+        toolkit.realSync();
+    }
+
+    static class DeadKeyListener extends KeyAdapter {
+
+        @Override
+        public void keyPressed(KeyEvent e) {
+            int keyCode = e.getKeyCode();
+            char keyChar = e.getKeyChar();
+
+            switch (state) {
+                case 0:
+                    if (keyCode != KeyEvent.VK_ALT) {
+                        throw new RuntimeException("Alt is not pressed.");
+                    }
+                    state++;
+                    break;
+                case 1:
+                    if (keyCode != KeyEvent.VK_DEAD_ACUTE) {
+                        throw new RuntimeException("Dead ACUTE is not pressed.");
+                    }
+                    if (keyChar != 0xB4) {
+                        throw new RuntimeException("Pressed char is not dead acute.");
+                    }
+
+                    state++;
+                    break;
+                case 2:
+                    if (keyCode != KeyEvent.VK_A) {
+                        throw new RuntimeException("A is not pressed.");
+                    }
+                    if (keyChar != 0xE1) {
+                        throw new RuntimeException("A char does not have ACCUTE accent");
+                    }
+                    state++;
+                    break;
+                default:
+                    throw new RuntimeException("Excessive keyPressed event.");
+            }
+        }
+
+        @Override
+        public void keyTyped(KeyEvent e) {
+            int keyCode = e.getKeyCode();
+            char keyChar = e.getKeyChar();
+
+            if (state == 3) {
+                if (keyCode != 0) {
+                    throw new RuntimeException("Key code should be undefined.");
+                }
+                if (keyChar != 0xE1) {
+                    throw new RuntimeException("A char does not have ACCUTE accent");
+                }
+            } else {
+                throw new RuntimeException("Wron number of keyTyped events.");
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/beans/Introspector/Test7193977.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,159 @@
+/*
+ * 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 7193977
+ * @summary Tests that generified property descriptors do not loose additional info
+ * @author Sergey Malenkov
+ */
+
+import java.awt.Image;
+import java.beans.BeanDescriptor;
+import java.beans.BeanInfo;
+import java.beans.EventSetDescriptor;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.MethodDescriptor;
+import java.beans.PropertyDescriptor;
+import java.util.Arrays;
+import java.util.List;
+
+public class Test7193977 {
+
+    private static final List<String> names = Arrays.asList("listType", "list", "value");
+
+    public static void main(String args[]) {
+        for (String name : names) {
+            test(Abstract.class, name);
+            test(Concrete.class, name);
+        }
+    }
+
+    private static void test(Class<?> type, String name) {
+        if (!Boolean.TRUE.equals(BeanUtils.getPropertyDescriptor(type, name).getValue("transient"))) {
+            throw new Error("property '" + name + "' is not transient");
+        }
+    }
+
+    public static final class Concrete extends Abstract<String> {
+    }
+
+    public static abstract class Abstract<T> {
+        private List<T> list;
+
+        public List<T> getList() {
+            return this.list;
+        }
+
+        public void setList(List<T> list) {
+            this.list = list;
+        }
+
+        public T getValue(int index) {
+            return (0 <= index) && (this.list != null) && (index < this.list.size())
+                    ? this.list.get(index)
+                    : null;
+        }
+
+        public void setValue(int index, T value) {
+            if ((0 <= index) && (this.list != null)) {
+                if (index == this.list.size()) {
+                    this.list.add(value);
+                }
+                else if (index < this.list.size()) {
+                    this.list.set(index, value);
+                }
+            }
+        }
+
+        public String getListType() {
+            return (this.list != null)
+                    ? this.list.getClass().getName()
+                    : null;
+        }
+
+        public void setListType(String type) throws Exception {
+            this.list = (type != null)
+                    ? (List<T>) Class.forName(type).newInstance()
+                    : null;
+        }
+    }
+
+    public static final class ConcreteBeanInfo extends Wrapper {
+        public ConcreteBeanInfo() throws IntrospectionException {
+            super(Concrete.class);
+        }
+    }
+
+    public static final class AbstractBeanInfo extends Wrapper {
+        public AbstractBeanInfo() throws IntrospectionException {
+            super(Abstract.class);
+            for (PropertyDescriptor pd : getPropertyDescriptors()) {
+                if (names.contains(pd.getName())) {
+                    pd.setValue("transient", Boolean.TRUE);
+                }
+            }
+        }
+    }
+
+    private static class Wrapper implements BeanInfo {
+        private final BeanInfo info;
+
+        Wrapper(Class<?> type) throws IntrospectionException {
+            this.info = Introspector.getBeanInfo(type, Introspector.IGNORE_IMMEDIATE_BEANINFO);
+        }
+
+        public BeanDescriptor getBeanDescriptor() {
+            return this.info.getBeanDescriptor();
+        }
+
+        public EventSetDescriptor[] getEventSetDescriptors() {
+            return this.info.getEventSetDescriptors();
+        }
+
+        public int getDefaultEventIndex() {
+            return this.info.getDefaultEventIndex();
+        }
+
+        public PropertyDescriptor[] getPropertyDescriptors() {
+            return this.info.getPropertyDescriptors();
+        }
+
+        public int getDefaultPropertyIndex() {
+            return this.info.getDefaultPropertyIndex();
+        }
+
+        public MethodDescriptor[] getMethodDescriptors() {
+            return this.info.getMethodDescriptors();
+        }
+
+        public BeanInfo[] getAdditionalBeanInfo() {
+            return this.info.getAdditionalBeanInfo();
+        }
+
+        public Image getIcon(int kind) {
+            return this.info.getIcon(kind);
+        }
+    }
+}
--- a/jdk/test/javax/imageio/metadata/BooleanAttributes.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/test/javax/imageio/metadata/BooleanAttributes.java	Wed Sep 19 12:41:54 2012 -0700
@@ -1,12 +1,10 @@
 /*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * 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.
+ * 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
--- a/jdk/test/javax/imageio/metadata/DOML3Node.java	Wed Sep 19 14:55:40 2012 +0100
+++ b/jdk/test/javax/imageio/metadata/DOML3Node.java	Wed Sep 19 12:41:54 2012 -0700
@@ -1,12 +1,10 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * 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.
+ * 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/GetChildNames.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,64 @@
+/*
+ * 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 4429876
+ * @run main GetChildNames
+ * @summary Tests that the getChildNames method of
+ * IIOMetadataFormatImpl returns null for a CHILD_POLICY_EMPTY node.
+ */
+
+import javax.imageio.metadata.IIOMetadataFormatImpl;
+import javax.imageio.ImageTypeSpecifier;
+
+public class GetChildNames {
+
+    public static void main(String argv[]) {
+        GCNFormatImpl fmt = new GCNFormatImpl("root", 1, 10);
+        fmt.addElement("cc", "root", fmt.CHILD_POLICY_EMPTY);
+
+        String[] result = fmt.getChildNames("cc");
+        if (result != null) {
+            throw new RuntimeException
+                ("Failed, result is not null: " + result);
+        }
+    }
+}
+
+class GCNFormatImpl extends IIOMetadataFormatImpl {
+
+    GCNFormatImpl(String root, int minChildren, int maxChildren) {
+        super(root, minChildren, maxChildren);
+    }
+
+    public void addElement(String elementName,
+                           String parentName, int childPolicy) {
+        super.addElement(elementName, parentName, childPolicy);
+    }
+
+    public boolean canNodeAppear(String elementName,
+                                 ImageTypeSpecifier imageType) {
+        return true;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/GetObjectMinValue.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,97 @@
+/*
+ * 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 4429875 7186799
+ * @compile -source 1.4 GetObjectMinValue.java
+ * @run main GetObjectMinValue
+ * @summary Tests the getObject{Min,Max}Value method of
+ * IIOMetadataFormatImpl for an inclusive range
+ */
+
+// Compiled with -source 1.4 to work around javac bug 5041233
+
+import javax.imageio.metadata.IIOMetadataFormatImpl;
+import javax.imageio.ImageTypeSpecifier;
+
+public class GetObjectMinValue {
+
+    public static void main(String argv[]) {
+        test(true, true);
+        test(true, false);
+        test(false, true);
+        test(false, false);
+    }
+
+    private static void test(boolean minInclusive, boolean maxInclusive) {
+        Integer defValue = new Integer(1);
+        Integer minValue = new Integer(0);
+        Integer maxValue = new Integer(10);
+
+        MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);
+
+        fmt.addObjectValue("root", defValue.getClass(), defValue,
+                           minValue, maxValue, minInclusive, maxInclusive);
+
+        try {
+            Integer act_min = (Integer)fmt.getObjectMinValue("root");
+            if (! act_min.equals(minValue))
+                throw new RuntimeException("invalid min value: " + act_min);
+        } catch (Throwable e) {
+            throw new RuntimeException
+                ("getObjectMinValue: unexpected exception: " + e);
+        }
+        try {
+            Integer act_max = (Integer)fmt.getObjectMaxValue("root");
+            if (! act_max.equals(maxValue))
+                throw new RuntimeException("invalid max value: " + act_max);
+        } catch (Throwable e) {
+            throw new RuntimeException
+                ("getObjectMaxValue: unexpected exception: " + e);
+        }
+    }
+
+    static class MyFormatImpl extends IIOMetadataFormatImpl {
+
+        MyFormatImpl(String root, int minChildren, int maxChildren) {
+            super(root, minChildren, maxChildren);
+        }
+
+        public void addObjectValue(String elementName,
+                                   Class classType, Object defaultValue,
+                                   Comparable minValue, Comparable maxValue,
+                                   boolean minInclusive, boolean maxInclusive) {
+            super.addObjectValue(elementName,
+                                 classType, defaultValue,
+                                 minValue, maxValue,
+                                 minInclusive, maxInclusive);
+        }
+
+        public boolean canNodeAppear(String elementName,
+                                     ImageTypeSpecifier imageType) {
+            return true;
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/IIOMetadataFormat/MetadataFormatTest.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+/*
+ * @bug 4929170
+ * @summary  Tests that user-supplied IIOMetadata implementations
+ *           is able to load correspnding IIOMetadataFormat implementations.
+ */
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+
+public class MetadataFormatTest {
+    public static void main(String[] args) throws Exception {
+        String codebase = args[0];
+        String code = args[1];
+
+        MetadataTest t = createTest(codebase, code);
+        try {
+            t.doTest();
+        } catch (IllegalStateException e) {
+            System.out.println("Test failed.");
+            e.printStackTrace();
+
+            System.exit(1);
+        }
+    }
+
+    protected static MetadataTest createTest(String codebase,
+                                             String code) throws Exception {
+        URL[] urls = { new File(codebase).toURL()};
+        ClassLoader loader = new URLClassLoader(urls);
+
+        Class ct = loader.loadClass(code);
+
+        return (MetadataTest)ct.newInstance();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/IIOMetadataFormat/MetadataFormatThreadTest.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+/*
+ * @bug 4929170
+ * @summary Tests that user-supplied IIOMetadata implementations
+ *           is able to load correspnding IIOMetadataFormat implementations.
+ */
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+
+public class MetadataFormatThreadTest implements Runnable {
+
+    String test_class;
+
+    public static void main(String[] args) throws Exception {
+        String codebase = args[0];
+        String code = args[1];
+
+        Thread t = createTest(codebase, code);
+        try {
+            t.start();
+        } catch (IllegalStateException e) {
+            System.out.println("Test failed.");
+            e.printStackTrace();
+
+            System.exit(1);
+        }
+    }
+
+    public MetadataFormatThreadTest(String c) {
+        test_class = c;
+    }
+
+    public void run() {
+        try {
+            ClassLoader loader = (ClassLoader)
+                java.security.AccessController.doPrivileged(
+                    new java.security.PrivilegedAction() {
+                            public Object run() {
+                                return Thread.currentThread().getContextClassLoader();
+                            }
+                        });
+
+            Class ct = loader.loadClass(test_class);
+
+            MetadataTest t = (MetadataTest)ct.newInstance();
+
+            t.doTest();
+        } catch (Exception e) {
+            System.out.println("Test failed.");
+            e.printStackTrace();
+            System.exit(1);
+        }
+    }
+
+    protected static Thread createTest(String codebase,
+                                             String code) throws Exception {
+
+        URL[] urls = { new File(codebase).toURL()};
+        final ClassLoader loader = new URLClassLoader(urls);
+
+        final Thread t = new Thread(new MetadataFormatThreadTest(code));
+        java.security.AccessController.doPrivileged(
+            new java.security.PrivilegedAction() {
+                    public Object run() {
+                        t.setContextClassLoader(loader);
+                        return null;
+                    }
+                });
+
+        return t;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/IIOMetadataFormat/MetadataTest.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+/*
+ * @bug       4929170
+ * @summary   Interface for user-supplied IIOMetadata
+ *            implementation tests.
+ */
+
+import java.io.IOException;
+
+public interface MetadataTest {
+    public void doTest() throws IOException;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/IIOMetadataFormat/UserPluginMetadataFormatTest.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,467 @@
+/*
+ * 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     4929170
+ * @summary Tests that user-supplied IIOMetadata implementations loaded by
+ *           system class loader (i.e. corresponding classes are available via
+ *           classpath) is able to load correspnding IIOMetadataFormat
+ *           implementations.
+ * @run     main UserPluginMetadataFormatTest
+ */
+
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.util.Iterator;
+import java.util.ListResourceBundle;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.Vector;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageReadParam;
+import javax.imageio.IIOException;
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.event.IIOReadWarningListener;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.metadata.IIOMetadataFormat;
+import javax.imageio.metadata.IIOMetadataFormatImpl;
+import javax.imageio.metadata.IIOInvalidTreeException;
+import javax.imageio.spi.ImageReaderSpi;
+import org.w3c.dom.Node;
+
+public class UserPluginMetadataFormatTest implements MetadataTest {
+
+    public static void main(String[] argv) throws IOException {
+        new UserPluginMetadataFormatTest().doTest();
+    }
+
+    public void doTest() throws IOException {
+
+        DummyImageReaderImpl reader;
+
+        reader = new DummyImageReaderImpl(new DummyImageReaderSpiImpl());
+
+        byte[] data = new byte[1024];
+        ByteArrayInputStream bais =
+            new ByteArrayInputStream(data);
+
+        reader.setInput(ImageIO.createImageInputStream(bais));
+        IIOMetadata metadata = reader.getImageMetadata(1);
+        if(metadata == null) {
+            throw new RuntimeException("IIOMetada is NULL");
+        }
+
+        String[] formatNames = metadata.getMetadataFormatNames();
+
+        for(int j=0; j<formatNames.length; j++) {
+
+            String formatName = formatNames[j];
+            System.out.println("\nFormat Names : " + formatName);
+
+            try {
+                IIOMetadataFormat metadataFormat =
+                    metadata.getMetadataFormat(formatName);
+                System.out.println("  Class Name " +
+                                   metadataFormat.getClass());
+            } catch(IllegalStateException ise) {
+                Throwable t = ise;
+                t.printStackTrace();
+                while(t.getCause() != null) {
+                    t = t.getCause();
+                    t.printStackTrace();
+                }
+                // test failed!
+                // stop applet!
+                System.out.println("Test faied.");
+                throw new RuntimeException("Test failed.", ise);
+            }
+        }
+    }
+
+    public static class DummyImageReaderImpl extends ImageReader {
+
+        public DummyImageReaderImpl(ImageReaderSpi originatingProvider) {
+            super(originatingProvider);
+        }
+
+        public int getNumImages(boolean allowSearch) throws IOException {
+            return 5;
+        }
+
+        public int getWidth(int imageIndex) throws IOException {
+            if (input == null)
+                throw new IllegalStateException();
+            if (imageIndex >= 5 || imageIndex < 0)
+                throw new IndexOutOfBoundsException();
+
+            return 10;
+        }
+
+        public int getHeight(int imageIndex) throws IOException {
+            if (input == null)
+                throw new IllegalStateException();
+            if (imageIndex >= 5 || imageIndex < 0)
+                throw new IndexOutOfBoundsException();
+
+            return 15;
+        }
+
+        public Iterator getImageTypes(int imageIndex) throws IOException {
+            if (input == null)
+                throw new IllegalStateException();
+            if (imageIndex >= 5 || imageIndex < 0)
+                throw new IndexOutOfBoundsException();
+
+            Vector imageTypes = new Vector();
+            imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType
+                           (BufferedImage.TYPE_BYTE_GRAY ));
+            return imageTypes.iterator();
+        }
+
+        public IIOMetadata getStreamMetadata() throws IOException {
+            return new DummyIIOMetadataImpl(true, null, null, null, null);
+        }
+
+        public IIOMetadata getImageMetadata(int imageIndex) throws IOException {
+
+            if (input == null)
+                throw new IllegalStateException();
+            if (imageIndex >= 5 || imageIndex < 0)
+                throw new IndexOutOfBoundsException();
+            if (seekForwardOnly) {
+                if (imageIndex < minIndex)
+                    throw new IndexOutOfBoundsException();
+                minIndex = imageIndex;
+            }
+            System.out.println("Current format class name " + DummyIIOMetadataFormatImpl.class.getName());
+            return new DummyIIOMetadataImpl(true,
+                                            DummyIIOMetadataFormatImpl.nativeMetadataFormatName,
+                                            DummyIIOMetadataFormatImpl.class.getName(),
+                                            null, null);
+        }
+
+
+        public BufferedImage read(int imageIndex, ImageReadParam param)
+          throws IOException {
+            if (input == null)
+                throw new IllegalStateException();
+            if (imageIndex >= 5 || imageIndex < 0)
+                throw new IndexOutOfBoundsException();
+            if (seekForwardOnly) {
+                if (imageIndex < minIndex)
+                    throw new IndexOutOfBoundsException();
+                minIndex = imageIndex;
+            }
+
+            return getDestination(param, getImageTypes(imageIndex), 10, 15);
+        }
+
+        // protected  methods - now public
+
+        public  boolean abortRequested() {
+            return super.abortRequested();
+        }
+
+        public  void clearAbortRequest() {
+            super.clearAbortRequest();
+        }
+
+        public  void processImageComplete() {
+            super.processImageComplete();
+        }
+
+        public  void processImageProgress(float percentageDone) {
+            super.processImageProgress(percentageDone);
+        }
+
+        public  void processImageStarted(int imageIndex) {
+            super.processImageStarted(imageIndex);
+        }
+
+        public  void processImageUpdate(BufferedImage theImage,
+                                        int minX,
+                                        int minY,
+                                        int width,
+                                        int height,
+                                        int periodX,
+                                        int periodY,
+                                        int[] bands) {
+            super.processImageUpdate(theImage,
+                                     minX,
+                                     minY,
+                                     width,
+                                     height,
+                                     periodX,
+                                     periodY,
+                                     bands);
+        }
+
+        public  void processPassComplete(BufferedImage theImage) {
+            super. processPassComplete(theImage);
+        }
+
+        public  void processPassStarted(BufferedImage theImage,
+                                        int pass, int minPass,
+                                        int maxPass,
+                                        int minX,
+                                        int minY,
+                                        int periodX,
+                                        int periodY,
+                                        int[] bands) {
+            super.processPassStarted(theImage,
+                                     pass,
+                                     minPass,
+                                     maxPass,
+                                     minX,
+                                     minY,
+                                     periodX,
+                                     periodY,
+                                     bands);
+        }
+
+        public  void processReadAborted() {
+            super.processReadAborted();
+        }
+
+        public  void processSequenceComplete() {
+            super.processSequenceComplete();
+        }
+
+        public  void processSequenceStarted(int minIndex) {
+            super.processSequenceStarted(minIndex);
+        }
+
+        public  void processThumbnailComplete() {
+            super.processThumbnailComplete();
+        }
+
+        public  void processThumbnailPassComplete(BufferedImage theThumbnail) {
+            super.processThumbnailPassComplete(theThumbnail);
+        }
+
+        public  void processThumbnailPassStarted(BufferedImage theThumbnail,
+                                                 int pass,
+                                                 int minPass,
+                                                 int maxPass,
+                                                 int minX,
+                                                 int minY,
+                                                 int periodX,
+                                                 int periodY,
+                                                 int[] bands) {
+            super.processThumbnailPassStarted(theThumbnail,
+                                              pass,
+                                              minPass,
+                                              maxPass,
+                                              minX,
+                                              minY,
+                                              periodX,
+                                              periodY,
+                                              bands);
+        }
+
+        public  void processThumbnailProgress(float percentageDone) {
+            super.processThumbnailProgress(percentageDone);
+        }
+
+        public  void processThumbnailStarted(int imageIndex, int thumbnailIndex) {
+            super.processThumbnailStarted(imageIndex, thumbnailIndex);
+        }
+
+        public  void processThumbnailUpdate(BufferedImage theThumbnail,
+                                            int minX,
+                                            int minY,
+                                            int width,
+                                            int height,
+                                            int periodX,
+                                            int periodY,
+                                            int[] bands) {
+            super.processThumbnailUpdate(theThumbnail,
+                                         minX,
+                                         minY,
+                                         width,
+                                         height,
+                                         periodX,
+                                         periodY,
+                                         bands);
+        }
+
+        public  void processWarningOccurred(String warning) {
+            super.processWarningOccurred(warning);
+        }
+
+
+
+        public static Rectangle getSourceRegion(ImageReadParam param,
+                                                int srcWidth,
+                                                int srcHeight) {
+            return ImageReader.getSourceRegion(param, srcWidth, srcHeight);
+        }
+
+        public static void computeRegions(ImageReadParam param,
+                                          int srcWidth,
+                                          int srcHeight,
+                                          BufferedImage image,
+                                          Rectangle srcRegion,
+                                          Rectangle destRegion) {
+            ImageReader.computeRegions(param,
+                                       srcWidth,
+                                       srcHeight,
+                                       image,
+                                       srcRegion,
+                                       destRegion);
+        }
+
+        public static void checkReadParamBandSettings(ImageReadParam param,
+                                                      int numSrcBands,
+                                                      int numDstBands) {
+            ImageReader.checkReadParamBandSettings( param,
+                                                    numSrcBands,
+                                                    numDstBands);
+        }
+
+        public static BufferedImage getDestination(ImageReadParam param,
+                                                   Iterator imageTypes,
+                                                   int width,
+                                                   int height)
+          throws IIOException {
+            return ImageReader.getDestination(param,
+                                              imageTypes,
+                                              width,
+                                              height);
+        }
+
+        public  void setAvailableLocales(Locale[] locales) {
+            if (locales == null || locales.length == 0)
+                availableLocales = null;
+            else
+                availableLocales = (Locale[])locales.clone();
+        }
+
+        public  void processWarningOccurred(String baseName, String keyword) {
+            super.processWarningOccurred(baseName, keyword);
+        }
+    }
+
+    public static class DummyIIOMetadataFormatImpl
+        extends IIOMetadataFormatImpl {
+        public static String nativeMetadataFormatName =
+        "javax_imageio_dummy_1.0";
+
+        private static IIOMetadataFormat instance = null;
+
+
+        private DummyIIOMetadataFormatImpl() {
+            super(DummyIIOMetadataFormatImpl.nativeMetadataFormatName,
+                  CHILD_POLICY_SOME);
+        }
+
+        public boolean canNodeAppear(String elementName,
+                                     ImageTypeSpecifier imageType) {
+            return false;
+        }
+
+        public static synchronized IIOMetadataFormat getInstance() {
+            if (instance == null) {
+                instance = new DummyIIOMetadataFormatImpl();
+            }
+            return instance;
+        }
+    }
+
+    public static class DummyIIOMetadataImpl extends IIOMetadata {
+
+        public DummyIIOMetadataImpl() {
+            super();
+        }
+
+        public DummyIIOMetadataImpl(boolean standardMetadataFormatSupported,
+                                    String nativeMetadataFormatName,
+                                    String nativeMetadataFormatClassName,
+                                    String[] extraMetadataFormatNames,
+                                    String[] extraMetadataFormatClassNames) {
+            super(standardMetadataFormatSupported,
+                  nativeMetadataFormatName,
+                  nativeMetadataFormatClassName,
+                  extraMetadataFormatNames,
+                  extraMetadataFormatClassNames);
+        }
+
+        public boolean isReadOnly() {
+            return true;
+        }
+
+        public Node getAsTree(String formatName) {
+            return null;
+        }
+
+        public void mergeTree(String formatName, Node root)
+          throws IIOInvalidTreeException {
+            throw new IllegalStateException();
+        }
+
+        public void reset() {
+            throw new IllegalStateException();
+        }
+    }
+
+    public static class DummyImageReaderSpiImpl extends ImageReaderSpi {
+
+        static final String[] names ={ "myformat" };
+
+        public DummyImageReaderSpiImpl() {
+            super("vendorName",
+                  "version",
+                  names,
+                  null,
+                  null,
+                  "DummyImageReaderImpl",
+                  STANDARD_INPUT_TYPE,
+                  null,
+                  true,
+                  null,
+                  null,
+                  null,
+                  null,
+                  true,
+                  null,
+                  null,
+                  null,
+                  null);
+        }
+        public boolean canDecodeInput(Object source)
+          throws IOException {
+            return true;
+        }
+        public ImageReader createReaderInstance(Object extension)
+          throws IOException {
+            return new DummyImageReaderImpl(this);
+        }
+        public String getDescription(Locale locale) {
+            return "DummyImageReaderSpiImpl";
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/IIOMetadataFormat/runMetadataFormatTest.sh	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,228 @@
+#!/bin/ksh -p
+#
+# 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        4929170 7078379
+#   @summary    Tests that user-supplied IIOMetadata implementations
+#               loaded by separate classloader is able to load correspnding 
+#               IIOMetadataFormat implementations.
+#   @author     Andrew Brygin
+#
+#   @compile    UserPluginMetadataFormatTest.java MetadataFormatTest.java MetadataTest.java
+#   @run shell/timeout=60 runMetadataFormatTest.sh
+
+# Note!!!! JavaCodeForYourTest_CHANGE_THIS.java must be changed or deleted.  
+# If there is any java code which will be executed during the test, it must 
+# be compiled by the line above.  If multiple .java files, separate the 
+# files by spaces on that line.  See testing page of AWT home page for
+# pointers to the testharness spec. and FAQ.
+# Note!!!! Change AppletDeadlock.sh to the name of your test!!!!
+
+# There are several resources which need to be present before many 
+#  shell scripts can run.  Following are examples of how to check for
+#  many common ones.
+# 
+# Note that the shell used is the Korn Shell, KSH
+#
+# Also note, it is recommended that make files NOT be used.  Rather,
+#  put the individual commands directly into this file.  That way,
+#  it is possible to use command line arguments and other shell tech-
+#  niques to find the compiler, etc on different systems.  For example,
+#  a different path could be used depending on whether this were a
+#  Solaris or Win32 machine, which is more difficult (if even possible)
+#  in a make file.  
+
+
+# Beginning of subroutines:
+status=1
+
+#Call this from anywhere to fail the test with an error message
+# usage: fail "reason why the test failed"
+fail() 
+ { echo "The test failed :-("
+   echo "$*" 1>&2
+   exit 1
+ } #end of fail()
+
+#Call this from anywhere to pass the test with a message
+# usage: pass "reason why the test passed if applicable"
+pass() 
+ { echo "The test passed!!!"
+   echo "$*" 1>&2
+   exit 0
+ } #end of pass()
+
+# end of subroutines
+
+
+# The beginning of the script proper
+
+# Checking for proper OS
+OS=`uname -s`
+case "$OS" in
+   SunOS )
+      VAR="One value for Sun"
+      DEFAULT_JDK=/none
+      #DEFAULT_JDK=/usr/local/java/jdk1.2/solaris
+      FILESEP="/"
+      ;;
+
+   Linux | Darwin  )
+      VAR="A different value for Linux"
+      DEFAULT_JDK=/none
+      #DEFAULT_JDK=/usr/local/java/jdk1.4/linux-i386
+      FILESEP="/"
+      ;;
+
+   Windows_95 | Windows_98 | Windows_NT | Windows_ME )
+      VAR="A different value for Win32"
+      DEFAULT_JDK=/none
+      #DEFAULT_JDK=/usr/local/java/jdk1.2/win32
+      FILESEP="\\"
+      ;;
+
+    CYGWIN* )
+      VAR="A different value for CYGWIN"
+      DEFAULT_JDK=/none
+      FILESEP="/"
+      ;;
+
+   # catch all other OSs
+   * )
+      echo "Unrecognized system!  $OS"
+      fail "Unrecognized system!  $OS"
+      ;;
+esac
+
+# check that some executable or other file you need is available, abort if not
+#  note that the name of the executable is in the fail string as well.
+# this is how to check for presence of the compiler, etc.
+#RESOURCE=`whence SomeProgramOrFileNeeded`
+#if [ "${RESOURCE}" = "" ] ; 
+#   then fail "Need SomeProgramOrFileNeeded to perform the test" ; 
+#fi
+
+# IT'S FINE TO DELETE THIS IF NOT NEEDED!
+# check if an environment variable you need is set, give it a default if not
+#if [ -z "${NEEDED_VAR}" ] ; then
+#   # The var is NOT set, so give it a default
+#   NEEDED_VAR=/some/default/value/such/as/a/path
+#fi
+
+# IT'S FINE TO DELETE THIS IF NOT NEEDED!
+#if [ -z "${NEEDED_LATER_VAR}" ] ; then
+#   # The var is NOT set, so give it a default
+#   # will need it in other scripts called from this one, so export it
+#   NEEDED_LATER_VAR="/a/different/path/note/the/quotes"
+#   export NEEDED_LATER_VAR
+#fi
+
+# Want this test to run standalone as well as in the harness, so do the 
+#  following to copy the test's directory into the harness's scratch directory 
+#  and set all appropriate variables:
+
+if [ -z "${TESTJAVA}" ] ; then
+   # TESTJAVA is not set, so the test is running stand-alone.
+   # TESTJAVA holds the path to the root directory of the build of the JDK
+   # to be tested.  That is, any java files run explicitly in this shell
+   # should use TESTJAVA in the path to the java interpreter.
+   # So, we'll set this to the JDK spec'd on the command line.  If none
+   # is given on the command line, tell the user that and use a cheesy
+   # default.
+   # THIS IS THE JDK BEING TESTED.
+   if [ -n "$1" ] ;
+      then TESTJAVA=$1
+      else echo "no JDK specified on command line so using default!"
+	 TESTJAVA=$DEFAULT_JDK
+   fi
+   TESTSRC=.
+   TESTCLASSES=.
+   STANDALONE=1;
+fi
+echo "JDK under test is: $TESTJAVA"
+
+#Deal with .class files:
+if [ -n "${STANDALONE}" ] ; 
+   then 
+   #if standalone, remind user to cd to dir. containing test before running it
+   echo "Just a reminder: cd to the dir containing this test when running it"
+   # then compile all .java files (if there are any) into .class files
+   if [ -a *.java ] ; 
+      then echo "Reminder, this test should be in its own directory with all"
+      echo "supporting files it needs in the directory with it."
+      ${TESTJAVA}/bin/javac ./*.java ; 
+   fi
+   # else in harness so copy all the class files from where jtreg put them
+   # over to the scratch directory this test is running in. 
+   else cp ${TESTCLASSES}/*.class . ;
+fi
+
+#if in test harness, then copy the entire directory that the test is in over 
+# to the scratch directory.  This catches any support files needed by the test.
+
+#if [ -z "${STANDALONE}" ] ; 
+#   then cp ${TESTSRC}/* . 
+#fi
+
+#Just before executing anything, make sure it has executable permission!
+chmod 777 ./*
+
+###############  YOUR TEST CODE HERE!!!!!!!  #############
+
+#All files required for the test should be in the same directory with
+# this file.  If converting a standalone test to run with the harness,
+# as long as all files are in the same directory and it returns 0 for
+# pass, you should be able to cut and paste it into here and it will
+# run with the test harness.
+
+# This is an example of running something -- test
+# The stuff below catches the exit status of test then passes or fails
+# this shell test as appropriate ( 0 status is considered a pass here )
+#./test # DELETE THIS LINE AND REPLACE WITH YOUR OWN COMMAND!!!
+
+if [ -d ./test_classes ] ; then 
+    rm -rf ./test_calsses
+fi
+
+mkdir ./test_classes
+ 
+# split application classes and test plugin classes
+mv ./UserPluginMetadataFormatTest*.class ./test_classes
+
+$TESTJAVA/bin/java MetadataFormatTest test_classes UserPluginMetadataFormatTest
+
+###############  END YOUR TEST CODE !!!!! ############
+status=$?
+
+# pass or fail the test based on status of the command
+if [ $status -eq "0" ];
+   then pass "Test passed - no stack trace printing"
+
+   else fail "Test failure - stack trace was printed"
+fi
+
+#For additional examples of how to write platform independent KSH scripts,
+# see the jtreg file itself.  It is a KSH script for both Solaris and Win32
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/IIOMetadataFormat/runMetadataFormatThreadTest.sh	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,229 @@
+#!/bin/ksh -p
+#
+# 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        4929170 7078379
+#   @summary    Tests that user-supplied IIOMetadata implementations 
+#                loaded by separate classloader in separate thread  
+#                is able to load correspnding IIOMetadataFormat 
+#                implementations.
+#   @author     Andrew Brygin
+#
+#   @compile    UserPluginMetadataFormatTest.java MetadataFormatThreadTest.java MetadataTest.java
+#   @run shell/timeout=60 runMetadataFormatThreadTest.sh
+
+# Note!!!! JavaCodeForYourTest_CHANGE_THIS.java must be changed or deleted.  
+# If there is any java code which will be executed during the test, it must 
+# be compiled by the line above.  If multiple .java files, separate the 
+# files by spaces on that line.  See testing page of AWT home page for
+# pointers to the testharness spec. and FAQ.
+# Note!!!! Change AppletDeadlock.sh to the name of your test!!!!
+
+# There are several resources which need to be present before many 
+#  shell scripts can run.  Following are examples of how to check for
+#  many common ones.
+# 
+# Note that the shell used is the Korn Shell, KSH
+#
+# Also note, it is recommended that make files NOT be used.  Rather,
+#  put the individual commands directly into this file.  That way,
+#  it is possible to use command line arguments and other shell tech-
+#  niques to find the compiler, etc on different systems.  For example,
+#  a different path could be used depending on whether this were a
+#  Solaris or Win32 machine, which is more difficult (if even possible)
+#  in a make file.  
+
+
+# Beginning of subroutines:
+status=1
+
+#Call this from anywhere to fail the test with an error message
+# usage: fail "reason why the test failed"
+fail() 
+ { echo "The test failed :-("
+   echo "$*" 1>&2
+   exit 1
+ } #end of fail()
+
+#Call this from anywhere to pass the test with a message
+# usage: pass "reason why the test passed if applicable"
+pass() 
+ { echo "The test passed!!!"
+   echo "$*" 1>&2
+   exit 0
+ } #end of pass()
+
+# end of subroutines
+
+
+# The beginning of the script proper
+
+# Checking for proper OS
+OS=`uname -s`
+case "$OS" in
+   SunOS )
+      VAR="One value for Sun"
+      DEFAULT_JDK=/none
+      #DEFAULT_JDK=/usr/local/java/jdk1.2/solaris
+      FILESEP="/"
+      ;;
+
+   Linux | Darwin )
+      VAR="A different value for Linux"
+      DEFAULT_JDK=/none
+      #DEFAULT_JDK=/usr/local/java/jdk1.4/linux-i386
+      FILESEP="/"
+      ;;
+
+   Windows_95 | Windows_98 | Windows_NT | Windows_ME )
+      VAR="A different value for Win32"
+      DEFAULT_JDK=/none
+      #DEFAULT_JDK=/usr/local/java/jdk1.2/win32
+      FILESEP="\\"
+      ;;
+    
+    CYGWIN* )
+      VAR="A different value for CYGWIN"
+      DEFAULT_JDK=/none
+      FILESEP="/"
+      ;;
+
+   # catch all other OSs
+   * )
+      echo "Unrecognized system!  $OS"
+      fail "Unrecognized system!  $OS"
+      ;;
+esac
+
+# check that some executable or other file you need is available, abort if not
+#  note that the name of the executable is in the fail string as well.
+# this is how to check for presence of the compiler, etc.
+#RESOURCE=`whence SomeProgramOrFileNeeded`
+#if [ "${RESOURCE}" = "" ] ; 
+#   then fail "Need SomeProgramOrFileNeeded to perform the test" ; 
+#fi
+
+# IT'S FINE TO DELETE THIS IF NOT NEEDED!
+# check if an environment variable you need is set, give it a default if not
+#if [ -z "${NEEDED_VAR}" ] ; then
+#   # The var is NOT set, so give it a default
+#   NEEDED_VAR=/some/default/value/such/as/a/path
+#fi
+
+# IT'S FINE TO DELETE THIS IF NOT NEEDED!
+#if [ -z "${NEEDED_LATER_VAR}" ] ; then
+#   # The var is NOT set, so give it a default
+#   # will need it in other scripts called from this one, so export it
+#   NEEDED_LATER_VAR="/a/different/path/note/the/quotes"
+#   export NEEDED_LATER_VAR
+#fi
+
+# Want this test to run standalone as well as in the harness, so do the 
+#  following to copy the test's directory into the harness's scratch directory 
+#  and set all appropriate variables:
+
+if [ -z "${TESTJAVA}" ] ; then
+   # TESTJAVA is not set, so the test is running stand-alone.
+   # TESTJAVA holds the path to the root directory of the build of the JDK
+   # to be tested.  That is, any java files run explicitly in this shell
+   # should use TESTJAVA in the path to the java interpreter.
+   # So, we'll set this to the JDK spec'd on the command line.  If none
+   # is given on the command line, tell the user that and use a cheesy
+   # default.
+   # THIS IS THE JDK BEING TESTED.
+   if [ -n "$1" ] ;
+      then TESTJAVA=$1
+      else echo "no JDK specified on command line so using default!"
+	 TESTJAVA=$DEFAULT_JDK
+   fi
+   TESTSRC=.
+   TESTCLASSES=.
+   STANDALONE=1;
+fi
+echo "JDK under test is: $TESTJAVA"
+
+#Deal with .class files:
+if [ -n "${STANDALONE}" ] ; 
+   then 
+   #if standalone, remind user to cd to dir. containing test before running it
+   echo "Just a reminder: cd to the dir containing this test when running it"
+   # then compile all .java files (if there are any) into .class files
+   if [ -a *.java ] ; 
+      then echo "Reminder, this test should be in its own directory with all"
+      echo "supporting files it needs in the directory with it."
+      ${TESTJAVA}/bin/javac ./*.java ; 
+   fi
+   # else in harness so copy all the class files from where jtreg put them
+   # over to the scratch directory this test is running in. 
+   else cp ${TESTCLASSES}/*.class . ;
+fi
+
+#if in test harness, then copy the entire directory that the test is in over 
+# to the scratch directory.  This catches any support files needed by the test.
+
+#if [ -z "${STANDALONE}" ] ; 
+#   then cp ${TESTSRC}/* . 
+#fi
+
+#Just before executing anything, make sure it has executable permission!
+chmod 777 ./*
+
+###############  YOUR TEST CODE HERE!!!!!!!  #############
+
+#All files required for the test should be in the same directory with
+# this file.  If converting a standalone test to run with the harness,
+# as long as all files are in the same directory and it returns 0 for
+# pass, you should be able to cut and paste it into here and it will
+# run with the test harness.
+
+# This is an example of running something -- test
+# The stuff below catches the exit status of test then passes or fails
+# this shell test as appropriate ( 0 status is considered a pass here )
+#./test # DELETE THIS LINE AND REPLACE WITH YOUR OWN COMMAND!!!
+
+if [ -d ./test_classes ] ; then 
+    rm -rf ./test_calsses
+fi
+
+mkdir ./test_classes
+ 
+# split application classes and test plugin classes
+mv ./UserPluginMetadataFormatTest*.class ./test_classes
+
+$TESTJAVA/bin/java MetadataFormatThreadTest test_classes UserPluginMetadataFormatTest
+
+###############  END YOUR TEST CODE !!!!! ############
+status=$?
+
+# pass or fail the test based on status of the command
+if [ $status -eq "0" ];
+   then pass "Test passed - no stack trace printing"
+
+   else fail "Test failure - stack trace was printed"
+fi
+
+#For additional examples of how to write platform independent KSH scripts,
+# see the jtreg file itself.  It is a KSH script for both Solaris and Win32
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/IIOMetadataFormatImplTest.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,206 @@
+/*
+ * 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 4403350 4403352 4436995 4438977
+ * @run main IIOMetadataFormatImplTest
+ * @summary Tests various methods of IIOMetadataFormatImpl:
+ *
+ * getElement{Min,Max}Children and getAttribute{Min,Max}Value
+ * getAttributeDescription
+ * getAttributeEnumerations
+ */
+
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.metadata.IIOMetadataFormat;
+import javax.imageio.metadata.IIOMetadataFormatImpl;
+
+public class IIOMetadataFormatImplTest {
+
+    public static void main(String[] args) {
+        test440335x();
+        test4436995();
+        test4438977();
+    }
+
+    static class IIOMetadataFormatImpl440335x extends IIOMetadataFormatImpl {
+
+        public IIOMetadataFormatImpl440335x() {
+            super("rootNode", 0, 1);
+            addElement("anElement", "rootNode", 20, 200);
+            addAttribute("anElement", "exclusiveAttr",
+                         IIOMetadataFormat.DATATYPE_INTEGER,
+                         true, null,
+                         "50", "500",
+                         false, false);
+            addAttribute("anElement", "minAttr",
+                         IIOMetadataFormat.DATATYPE_INTEGER,
+                         true, null,
+                         "60", "600",
+                         true, false);
+            addAttribute("anElement", "maxAttr",
+                         IIOMetadataFormat.DATATYPE_INTEGER,
+                         true, null,
+                         "70", "700",
+                         false, true);
+            addAttribute("anElement", "minMaxAttr",
+                         IIOMetadataFormat.DATATYPE_INTEGER,
+                         true, null,
+                         "80", "800",
+                         true, true);
+        }
+
+        public boolean canNodeAppear(String nodeName,
+                                     ImageTypeSpecifier imageType) {
+            return true;
+        }
+    }
+
+    private static void test440335x() {
+        IIOMetadataFormat format = new IIOMetadataFormatImpl440335x();
+
+        // Check that correct value is returned
+        if (format.getElementMinChildren("anElement") != 20) {
+            throw new RuntimeException("Error on getElementMinChildren!");
+        }
+        if (format.getElementMaxChildren("anElement") != 200) {
+            throw new RuntimeException("Error on getElementMaxChildren!");
+        }
+
+        // Check that correct value is returned and no exception is thrown
+        try {
+            if (!format.getAttributeMinValue("anElement",
+                                             "exclusiveAttr").equals("50")) {
+                throw new RuntimeException("Error on exclusiveAttr min!");
+            }
+            if (!format.getAttributeMaxValue("anElement",
+                                             "exclusiveAttr").equals("500")) {
+                throw new RuntimeException("Error on exclusiveAttr max!");
+            }
+            if (!format.getAttributeMinValue("anElement",
+                                             "minAttr").equals("60")) {
+                throw new RuntimeException("Error on minAttr min!");
+            }
+            if (!format.getAttributeMaxValue("anElement",
+                                             "minAttr").equals("600")) {
+                throw new RuntimeException("Error on minAttr max!");
+            }
+            if (!format.getAttributeMinValue("anElement",
+                                             "maxAttr").equals("70")) {
+                throw new RuntimeException("Error on maxAttr min!");
+            }
+            if (!format.getAttributeMaxValue("anElement",
+                                             "maxAttr").equals("700")) {
+                throw new RuntimeException("Error on maxAttr max!");
+            }
+            if (!format.getAttributeMinValue("anElement",
+                                             "minMaxAttr").equals("80")) {
+                throw new RuntimeException("Error on minMaxAttr min!");
+            }
+            if (!format.getAttributeMaxValue("anElement",
+                                             "minMaxAttr").equals("800")) {
+                throw new RuntimeException("Error on minMaxAttr max!");
+            }
+        } catch (IllegalStateException e) {
+            throw new RuntimeException("Got IllegalStateException!");
+        }
+    }
+
+    static class IIOMetadataFormatImpl4436995 extends IIOMetadataFormatImpl {
+
+        public IIOMetadataFormatImpl4436995(String root,
+                                            int minChildren, int maxChildren) {
+            super(root, minChildren, maxChildren);
+        }
+
+        public void addAttribute(String elementName,
+                                 String attrName,
+                                 int dataType,
+                                 boolean required,
+                                 int listMinLength, int listMaxLength) {
+            super.addAttribute(elementName,
+                               attrName,
+                               dataType,
+                               required, listMinLength,
+                               listMaxLength);
+        }
+
+        public boolean canNodeAppear(String elementName,
+                                     ImageTypeSpecifier imageType) {
+            return true;
+        }
+    }
+
+    private static void test4436995() {
+        String result;
+
+        IIOMetadataFormatImpl4436995 fmt =
+            new IIOMetadataFormatImpl4436995("root", 1, 10);
+        fmt.addAttribute("root", "attr", fmt.DATATYPE_INTEGER, true, 2, 5);
+        try {
+            result = fmt.getAttributeDescription("root", "non-existent", null);
+            throw new RuntimeException("Failed to get IAE!");
+        } catch(IllegalArgumentException e) {
+        }
+    }
+
+    static class IIOMetadataFormatImpl4438977 extends IIOMetadataFormatImpl {
+
+        public IIOMetadataFormatImpl4438977(String root,
+                                            int minChildren, int maxChildren) {
+            super(root, minChildren, maxChildren);
+        }
+
+        public void addAttribute(String elementName,
+                                 String attrName,
+                                 int dataType,
+                                 boolean required,
+                                 int listMinLength, int listMaxLength) {
+            super.addAttribute(elementName,
+                               attrName,
+                               dataType,
+                               required, listMinLength,
+                               listMaxLength);
+        }
+
+        public boolean canNodeAppear(String elementName,
+                                     ImageTypeSpecifier imageType) {
+            return true;
+        }
+    }
+
+    private static void test4438977() {
+        String[] result;
+
+        IIOMetadataFormatImpl4438977 fmt =
+            new IIOMetadataFormatImpl4438977("root", 1, 10);
+        fmt.addAttribute("root", "attr", fmt.DATATYPE_INTEGER, true, 2, 5);
+        try {
+            result = fmt.getAttributeEnumerations("root", "attr");
+            throw new RuntimeException("Failed to get IAE!");
+        } catch(IllegalArgumentException e) {
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/MetadataFormatPrinter.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,505 @@
+/*
+ * 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.
+ */
+
+//
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.metadata.IIOMetadataFormat;
+import javax.imageio.metadata.IIOMetadataFormatImpl;
+import javax.imageio.spi.IIORegistry;
+import javax.imageio.spi.ImageReaderSpi;
+import com.sun.imageio.plugins.png.PNGMetadata;
+
+public class MetadataFormatPrinter {
+
+    private int indentLevel = 0;
+
+    private int column = 0;
+
+    private PrintStream out;
+
+    private static final int maxColumn = 75;
+
+    private static String[] dataTypeNames = {
+        "String", "Boolean", "Integer", "Float", "Double"
+    };
+
+    // "Infinite" values
+    private static String maxInteger = Integer.toString(Integer.MAX_VALUE);
+
+    public MetadataFormatPrinter(PrintStream out) {
+        this.out = out;
+    }
+
+    private void println() {
+        out.println();
+        column = 0;
+    }
+
+    private void println(String s) {
+        out.println(s);
+        column = 0;
+    }
+
+    private void printWrapped(String in, int leftIndent) {
+        StringTokenizer t = new StringTokenizer(in);
+        while (t.hasMoreTokens()) {
+            String s = t.nextToken();
+            int length = s.length();
+            if (column + length > maxColumn) {
+                println();
+                indent();
+                for (int i = 0; i < leftIndent; i++) {
+                    print(" ");
+                }
+            }
+            out.print(s);
+            out.print(" ");
+            column += length + 1;
+        }
+    }
+
+    private void print(String s) {
+        int length = s.length();
+        if (column + length > maxColumn) {
+            println();
+            indent();
+            print("  ");
+        }
+        out.print(s);
+        column += length;
+    }
+
+    private void print(IIOMetadataFormat format) {
+        String rootName = format.getRootName();
+        println("<!DOCTYPE \"" +
+                           rootName +
+                           "\" [");
+        ++indentLevel;
+        print(format, rootName);
+        --indentLevel;
+        print("]>");
+        println();
+        println();
+    }
+
+    private void indent() {
+        for (int i = 0; i < indentLevel; i++) {
+            out.print("  ");
+            column += 2;
+        }
+    }
+
+    private void printElementInfo(IIOMetadataFormat format,
+                                  String elementName) {
+        println();
+        indent();
+        print("<!ELEMENT \"" +
+              elementName +
+              "\"");
+
+        String[] childNames = format.getChildNames(elementName);
+        boolean hasChildren = true;
+        String separator = " "; // symbol to place between children
+        String terminator = ""; // symbol to follow last child
+        String repeater = ""; // "*" if repeating
+
+        switch (format.getChildPolicy(elementName)) {
+        case IIOMetadataFormat.CHILD_POLICY_EMPTY:
+            hasChildren = false;
+            break;
+        case IIOMetadataFormat.CHILD_POLICY_ALL:
+            separator = ", ";
+            break;
+        case IIOMetadataFormat.CHILD_POLICY_SOME:
+            separator = "?, ";
+            terminator = "?";
+            break;
+        case IIOMetadataFormat.CHILD_POLICY_CHOICE:
+            separator = " | ";
+            break;
+        case IIOMetadataFormat.CHILD_POLICY_SEQUENCE:
+            separator = " | ";
+            repeater = "*";
+            break;
+        case IIOMetadataFormat.CHILD_POLICY_REPEAT:
+            repeater = "*";
+            break;
+        default:
+            break;
+        }
+
+        if (hasChildren) {
+            print(" (");
+            for (int i = 0; i < childNames.length - 1; i++) {
+                print(childNames[i] + separator);
+            }
+            print(childNames[childNames.length - 1] + terminator);
+            print(")" + repeater + ">");
+        } else {
+            print(" EMPTY>");
+        }
+        println();
+
+        String description = format.getElementDescription(elementName, null);
+        if (description != null) {
+            ++indentLevel;
+            indent();
+            printWrapped("<!-- " + description + " -->", 5);
+            println();
+            --indentLevel;
+        }
+        if (format.getChildPolicy(elementName) ==
+            IIOMetadataFormat.CHILD_POLICY_REPEAT) {
+            int minChildren = format.getElementMinChildren(elementName);
+            if (minChildren != 0) {
+                indent();
+                println("  <!-- Min children: " +
+                        minChildren +
+                        " -->");
+            }
+            int maxChildren = format.getElementMaxChildren(elementName);
+            if (maxChildren != Integer.MAX_VALUE) {
+                indent();
+                println("  <!-- Max children: " +
+                        maxChildren +
+                        " -->");
+            }
+        }
+    }
+
+    private void printAttributeInfo(IIOMetadataFormat format,
+                                    String elementName,
+                                    String attrName) {
+        indent();
+        print("<!ATTLIST \"" +
+              elementName +
+              "\" \"" +
+              attrName +
+              "\"");
+
+        int attrValueType =
+            format.getAttributeValueType(elementName, attrName);
+        switch (attrValueType) {
+        case IIOMetadataFormat.VALUE_NONE:
+            throw new RuntimeException
+                ("Encountered VALUE_NONE for an attribute!");
+            // break;
+        case IIOMetadataFormat.VALUE_ARBITRARY:
+            print(" #CDATA");
+            break;
+        case IIOMetadataFormat.VALUE_RANGE:
+        case IIOMetadataFormat.VALUE_RANGE_MIN_INCLUSIVE:
+        case IIOMetadataFormat.VALUE_RANGE_MAX_INCLUSIVE:
+        case IIOMetadataFormat.VALUE_RANGE_MIN_MAX_INCLUSIVE:
+            print(" #CDATA");
+            break;
+        case IIOMetadataFormat.VALUE_ENUMERATION:
+            print(" (");
+            String[] attrValues =
+                format.getAttributeEnumerations(elementName, attrName);
+            for (int j = 0; j < attrValues.length - 1; j++) {
+                print("\"" + attrValues[j] + "\" | ");
+            }
+            print("\"" + attrValues[attrValues.length - 1] + "\")");
+            break;
+        case IIOMetadataFormat.VALUE_LIST:
+            print(" #CDATA");
+            break;
+        default:
+            throw new RuntimeException
+                ("Encountered unknown value type for an attribute!");
+            // break;
+        }
+
+        String defaultValue =
+            format.getAttributeDefaultValue(elementName, attrName);
+        if (defaultValue != null) {
+            print(" ");
+            print("\"" + defaultValue + "\"");
+        } else {
+            if (format.isAttributeRequired(elementName, attrName)) {
+                print(" #REQUIRED");
+            } else {
+                print(" #IMPLIED");
+            }
+        }
+        println(">");
+
+        String description = format.getAttributeDescription(elementName,
+                                                            attrName,
+                                                            null);
+        if (description != null) {
+            ++indentLevel;
+            indent();
+            printWrapped("<!-- " + description + " -->", 5);
+            println();
+            --indentLevel;
+        }
+
+        int dataType = format.getAttributeDataType(elementName, attrName);
+
+        switch (attrValueType) {
+        case IIOMetadataFormat.VALUE_ARBITRARY:
+            indent();
+            println("  <!-- Data type: " + dataTypeNames[dataType] + " -->");
+            break;
+
+        case IIOMetadataFormat.VALUE_RANGE:
+        case IIOMetadataFormat.VALUE_RANGE_MIN_INCLUSIVE:
+        case IIOMetadataFormat.VALUE_RANGE_MAX_INCLUSIVE:
+        case IIOMetadataFormat.VALUE_RANGE_MIN_MAX_INCLUSIVE:
+            indent();
+            println("  <!-- Data type: " + dataTypeNames[dataType] + " -->");
+
+            boolean minInclusive =
+                (attrValueType &
+                 IIOMetadataFormat.VALUE_RANGE_MIN_INCLUSIVE_MASK) != 0;
+            boolean maxInclusive =
+                (attrValueType &
+                 IIOMetadataFormat.VALUE_RANGE_MAX_INCLUSIVE_MASK) != 0;
+            indent();
+            println("  <!-- Min value: " +
+                    format.getAttributeMinValue(elementName, attrName) +
+                    " " +
+                    (minInclusive ? "(inclusive)" : "(exclusive)") +
+                    " -->");
+            String maxValue =
+                format.getAttributeMaxValue(elementName, attrName);
+            // Hack: don't print "infinite" max values
+            if (dataType != IIOMetadataFormat.DATATYPE_INTEGER ||
+                !maxValue.equals(maxInteger)) {
+                indent();
+                println("  <!-- Max value: " +
+                        maxValue +
+                        " " +
+                        (maxInclusive ? "(inclusive)" : "(exclusive)") +
+                        " -->");
+            }
+            break;
+
+        case IIOMetadataFormat.VALUE_LIST:
+            indent();
+            println("  <!-- Data type: List of " + dataTypeNames[dataType] + " -->");
+
+            int minLength =
+                format.getAttributeListMinLength(elementName, attrName);
+            if (minLength != 0) {
+                indent();
+                println("  <!-- Min length: " +
+                        minLength +
+                        " -->");
+            }
+            int maxLength =
+                format.getAttributeListMaxLength(elementName, attrName);
+            if (maxLength != Integer.MAX_VALUE) {
+                indent();
+                println("  <!-- Max length: " +
+                        maxLength +
+                        " -->");
+            }
+            break;
+        }
+    }
+
+    private void printObjectInfo(IIOMetadataFormat format,
+                                 String elementName) {
+        int objectType = format.getObjectValueType(elementName);
+        if (objectType == IIOMetadataFormat.VALUE_NONE) {
+            return;
+        }
+
+        Class objectClass = format.getObjectClass(elementName);
+        if (objectClass != null) {
+            indent();
+            if (objectType == IIOMetadataFormat.VALUE_LIST) {
+                println("  <!-- User object: array of " +
+                        objectClass.getName() +
+                        " -->");
+            } else {
+                println("  <!-- User object: " +
+                        objectClass.getName() +
+                        " -->");
+            }
+
+            Object defaultValue = format.getObjectDefaultValue(elementName);
+            if (defaultValue != null) {
+                indent();
+                println("  <!-- Default value: " +
+                        defaultValue.toString() +
+                        " -->");
+            }
+
+            switch (objectType) {
+            case IIOMetadataFormat.VALUE_RANGE:
+                indent();
+                println("  <!-- Min value: " +
+                        format.getObjectMinValue(elementName).toString() +
+                        " -->");
+                indent();
+                println("  <!-- Max value: " +
+                        format.getObjectMaxValue(elementName).toString() +
+                        " -->");
+                break;
+
+            case IIOMetadataFormat.VALUE_ENUMERATION:
+                Object[] enums = format.getObjectEnumerations(elementName);
+                for (int i = 0; i < enums.length; i++) {
+                    indent();
+                    println("  <!-- Enumerated value: " +
+                            enums[i].toString() +
+                            " -->");
+                }
+                break;
+
+            case IIOMetadataFormat.VALUE_LIST:
+                int minLength = format.getObjectArrayMinLength(elementName);
+                if (minLength != 0) {
+                    indent();
+                    println("  <!-- Min length: " +
+                            minLength +
+                            " -->");
+                }
+                int maxLength = format.getObjectArrayMaxLength(elementName);
+                if (maxLength != Integer.MAX_VALUE) {
+                    indent();
+                    println("  <!-- Max length: " +
+                            maxLength +
+                            " -->");
+                }
+                break;
+            }
+        }
+    }
+
+    // Set of elements that have been printed already
+    Set printedElements = new HashSet();
+
+    // Set of elements that have been scheduled to be printed
+    Set scheduledElements = new HashSet();
+
+    private void print(IIOMetadataFormat format,
+                       String elementName) {
+        // Don't print elements more than once
+        if (printedElements.contains(elementName)) {
+            return;
+        }
+        printedElements.add(elementName);
+
+        // Add the unscheduled children of this node to a list,
+        // and mark them as scheduled
+        List children = new ArrayList();
+        String[] childNames = format.getChildNames(elementName);
+        if (childNames != null) {
+            for (int i = 0; i < childNames.length; i++) {
+                String childName = childNames[i];
+                if (!scheduledElements.contains(childName)) {
+                    children.add(childName);
+                    scheduledElements.add(childName);
+                }
+            }
+        }
+
+        printElementInfo(format, elementName);
+        printObjectInfo(format, elementName);
+
+        ++indentLevel;
+        String[] attrNames = format.getAttributeNames(elementName);
+        for (int i = 0; i < attrNames.length; i++) {
+            printAttributeInfo(format, elementName, attrNames[i]);
+        }
+
+        // Recurse on child nodes
+        Iterator iter = children.iterator();
+        while (iter.hasNext()) {
+            print(format, (String)iter.next());
+        }
+        --indentLevel;
+    }
+
+    public static void main(String[] args) {
+        IIOMetadataFormat format = null;
+        if (args.length == 0 || args[0].equals("javax_imageio_1.0")) {
+            format = IIOMetadataFormatImpl.getStandardFormatInstance();
+        } else {
+            IIORegistry registry = IIORegistry.getDefaultInstance();
+            Iterator iter = registry.getServiceProviders(ImageReaderSpi.class,
+                                                         false);
+            while (iter.hasNext()) {
+                ImageReaderSpi spi = (ImageReaderSpi)iter.next();
+                if (args[0].equals
+                    (spi.getNativeStreamMetadataFormatName())) {
+                    System.out.print(spi.getDescription(null));
+                    System.out.println(": native stream format");
+                    format = spi.getStreamMetadataFormat(args[0]);
+                    break;
+                }
+
+                String[] extraStreamFormatNames =
+                    spi.getExtraStreamMetadataFormatNames();
+                if (extraStreamFormatNames != null &&
+                    Arrays.asList(extraStreamFormatNames).
+                    contains(args[0])) {
+                    System.out.print(spi.getDescription(null));
+                    System.out.println(": extra stream format");
+                    format = spi.getStreamMetadataFormat(args[0]);
+                    break;
+                }
+
+                if (args[0].equals
+                    (spi.getNativeImageMetadataFormatName())) {
+                    System.out.print(spi.getDescription(null));
+                    System.out.println(": native image format");
+                    format = spi.getImageMetadataFormat(args[0]);
+                    break;
+                }
+
+                String[] extraImageFormatNames =
+                    spi.getExtraImageMetadataFormatNames();
+                if (extraImageFormatNames != null &&
+                    Arrays.asList(extraImageFormatNames).contains(args[0])) {
+                    System.out.print(spi.getDescription(null));
+                    System.out.println(": extra image format");
+                    format = spi.getImageMetadataFormat(args[0]);
+                    break;
+                }
+            }
+        }
+
+        if (format == null) {
+            System.err.println("Unknown format: " + args[0]);
+            System.exit(0);
+        }
+
+        MetadataFormatPrinter printer = new MetadataFormatPrinter(System.out);
+        printer.print(format);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/ObjectArrayMaxLength.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,57 @@
+/*
+ * 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 4406353
+ * @run main ObjectArrayMaxLength
+ * @summary Tests the getObjectArrayMaxLength method of
+ * IIOMetadataFormatImpl
+ */
+
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.metadata.IIOMetadataFormat;
+import javax.imageio.metadata.IIOMetadataFormatImpl;
+
+class MyIIOMetadataFormatImpl extends IIOMetadataFormatImpl {
+
+    MyIIOMetadataFormatImpl() {
+        super("root", CHILD_POLICY_EMPTY);
+        addObjectValue("root", byte.class, 123, 321);
+    }
+
+    public boolean canNodeAppear(String nodeName, ImageTypeSpecifier type) {
+        return true;
+    }
+}
+
+public class ObjectArrayMaxLength {
+
+    public static void main(String[] args) {
+        IIOMetadataFormat f = new MyIIOMetadataFormatImpl();
+        if (f.getObjectArrayMaxLength("root") != 321) {
+            throw new RuntimeException
+                ("Bad value for getObjectArrayMaxLength!");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/RegisteredFormatsTest.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,128 @@
+/*
+ * 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      5017991
+ * @summary  This test verifies two things:
+ *            a) we can get MetadataFormat classes for
+ *                each registered metadata format.
+ *            b) all metadata formats for standard plugins
+ *                are registered.
+ * @run main RegisteredFormatsTest
+ */
+
+import javax.imageio.spi.IIORegistry;
+import javax.imageio.spi.ImageReaderSpi;
+import javax.imageio.metadata.IIOMetadataFormat;
+import java.util.Iterator;
+import java.util.Hashtable;
+import java.util.Enumeration;
+
+public class RegisteredFormatsTest {
+
+    private static Hashtable fmts;
+
+    public static void main(String[] args) {
+        fmts = new Hashtable();
+
+        fmts.put("javax_imageio_jpeg_stream_1.0", Boolean.FALSE);
+        fmts.put("javax_imageio_jpeg_image_1.0",  Boolean.FALSE);
+        fmts.put("javax_imageio_png_1.0",         Boolean.FALSE);
+        fmts.put("javax_imageio_bmp_1.0",         Boolean.FALSE);
+        fmts.put("javax_imageio_wbmp_1.0",        Boolean.FALSE);
+        fmts.put("javax_imageio_gif_stream_1.0",  Boolean.FALSE);
+        fmts.put("javax_imageio_gif_image_1.0",   Boolean.FALSE);
+
+        IIORegistry registry = IIORegistry.getDefaultInstance();
+        Iterator iter = registry.getServiceProviders(ImageReaderSpi.class,
+                                                     false);
+        while(iter.hasNext()) {
+            ImageReaderSpi spi = (ImageReaderSpi)iter.next();
+            String fmt_name;
+            fmt_name = spi.getNativeStreamMetadataFormatName();
+            testStreamMetadataFormat(spi, fmt_name);
+
+            fmt_name = spi.getNativeImageMetadataFormatName();
+            testImageMetadataFormat(spi, fmt_name);
+
+            String[] fmt_names;
+            fmt_names = spi.getExtraStreamMetadataFormatNames();
+            for (int i=0; fmt_names != null && i < fmt_names.length; i++) {
+                testStreamMetadataFormat(spi, fmt_names[i]);
+            }
+
+            fmt_names = spi.getExtraImageMetadataFormatNames();
+            for (int i=0; fmt_names != null && i < fmt_names.length; i++) {
+                testImageMetadataFormat(spi, fmt_names[i]);
+            }
+        }
+        Enumeration keys = fmts.keys();
+        while (keys.hasMoreElements()) {
+            String key = (String)keys.nextElement();
+            boolean val = ((Boolean)fmts.get(key)).booleanValue();
+            if (!val) {
+                throw new RuntimeException("Test failed: format " +
+                                           key + "is not registered.");
+            }
+        }
+    }
+
+    private static void testStreamMetadataFormat(ImageReaderSpi spi,
+                                                 String fmt_name) {
+        if (fmt_name == null) {
+            return;
+        }
+        try {
+            testMetadataFormat(spi.getStreamMetadataFormat(fmt_name),
+                               fmt_name);
+        } catch (Exception e) {
+            throw new RuntimeException("Test failed for " + fmt_name,
+                                       e);
+        }
+    }
+
+    private static void testImageMetadataFormat(ImageReaderSpi spi,
+                                                String fmt_name) {
+        if (fmt_name == null) {
+            return;
+        }
+        try {
+            testMetadataFormat(spi.getImageMetadataFormat(fmt_name),
+                               fmt_name);
+        } catch (Exception e) {
+            throw new RuntimeException("Test failed for " + fmt_name,
+                                       e);
+        }
+    }
+    private static void testMetadataFormat(IIOMetadataFormat fmt,
+                                           String fmt_name) {
+        System.out.print(fmt_name + "...");
+        if (fmt != null) {
+            fmts.put(fmt_name, Boolean.TRUE);
+            System.out.println("Ok");
+        } else {
+            throw new RuntimeException("Test failed for " + fmt_name);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/RemoveElement.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,86 @@
+/*
+ * 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 4432628 7186799
+ * @run main RemoveElement
+ * @summary Checks if ImageMetadataFormatImpl.removeElement properly
+ * removes the element from its parent's child list.
+ */
+
+import javax.imageio.metadata.IIOMetadataFormatImpl;
+import javax.imageio.metadata.IIOMetadataFormat;
+import javax.imageio.ImageTypeSpecifier;
+
+public class RemoveElement {
+
+    public static void main(String[] args) {
+        String elem = "elem2";
+        int policy = IIOMetadataFormat.CHILD_POLICY_SOME;
+        MyFormatImpl fmt = new MyFormatImpl("root", 1, 10);
+        fmt.addElement("elem1", "root", policy);
+        fmt.addElement(elem, "root", policy);
+        fmt.removeElement("elem1");
+
+        boolean gotIAE = false;
+        try {
+            fmt.getChildPolicy("elem1");
+        } catch (IllegalArgumentException e) {
+            gotIAE = true;
+        }
+        if (!gotIAE) {
+            throw new RuntimeException("Element is still present!");
+        }
+        String[] chNames = fmt.getChildNames("root");
+        if (chNames.length != 1) {
+            throw new RuntimeException("Root still has more than 1 child!");
+        }
+        if (!elem.equals(chNames[0])) {
+            throw new RuntimeException("Root's remaining child is incorrect!");
+        }
+    }
+
+    static class MyFormatImpl extends IIOMetadataFormatImpl {
+
+        MyFormatImpl(String root, int minChildren, int maxChildren) {
+            super(root, minChildren, maxChildren);
+        }
+
+        public void addElement(String elementName,
+                               String parentName,
+                               int childPolicy) {
+            super.addElement(elementName, parentName, childPolicy);
+        }
+
+        public void removeElement(String elementName) {
+            super.removeElement(elementName);
+        }
+
+        public boolean canNodeAppear(String elementName,
+                                     ImageTypeSpecifier imageType) {
+            return true;
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/imageio/metadata/SetAttributeNode.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,175 @@
+/*
+ * 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 4507256
+ * @run main SetAttributeNode
+ * @summary Tests the functionality of IIOMetadataNode.setAttributeNode().
+ * Four separate tests are involved:
+ *   1) Tests whether a DOMException.INUSE_ATTRIBUTE_ERR is thrown if newAttr
+ *      is already an attribute of another Element object.
+ *   2) Tests whether setAttributeNode() returns the old attribute if it is
+ *      replaced.
+ *   3) Tests whether setAttributeNode() returns null if the new attribute is
+ *      not replacing an existing attribute.
+ *   4) Tests whether the new attribute successfully replaces an existing one.
+ */
+
+import javax.imageio.metadata.IIOMetadataNode;
+import org.w3c.dom.Attr;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
+import org.w3c.dom.TypeInfo;
+
+public class SetAttributeNode {
+
+    public static void test1() {
+        IIOMetadataNode parent = new IIOMetadataNode("parent");
+        IIOMetadataNode elem   = new IIOMetadataNode("elem");
+
+        MyAttrNode attrNode = new MyAttrNode("name", "value");
+        elem.setAttributeNode(attrNode);
+        attrNode.setOwnerElement(elem);
+
+        try {
+            parent.setAttributeNode(attrNode);
+        } catch (DOMException e) {
+            if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) {
+                throw new RuntimeException("Test 1 failed: " +
+                                           "Invalid exception code: " +
+                                           e.code);
+            }
+            return;
+        }
+
+        throw new RuntimeException("Test 1 failed: DOMException not thrown");
+    }
+
+    public static void test2() {
+        String name = "attr";
+        String oldValue = "old value";
+        String newValue = "new value";
+        Attr retAttr;
+
+        IIOMetadataNode parent = new IIOMetadataNode("parent");
+        MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
+        MyAttrNode attrNode2 = new MyAttrNode(name, newValue);
+
+        retAttr = parent.setAttributeNode(attrNode1);
+        retAttr = parent.setAttributeNode(attrNode2);
+
+        String actName = retAttr.getNodeName();
+        String actValue = retAttr.getValue();
+
+        if (!actName.equals(name) || !actValue.equals(oldValue)) {
+            throw new RuntimeException("Test 2 failed: Invalid attribute " +
+                                       "returned: " +
+                                       "(name: " + actName +
+                                       ", value: " + actValue + ")");
+        }
+    }
+
+    public static void test3() {
+        IIOMetadataNode parent = new IIOMetadataNode("parent");
+        MyAttrNode attrNode = new MyAttrNode("name", "value");
+        Attr retAttr = parent.setAttributeNode(attrNode);
+
+        if (retAttr != null) {
+            throw new RuntimeException("Test 3 failed: Return value is " +
+                                       "non-null");
+        }
+    }
+
+    public static void test4() {
+        String name = "name";
+        String correctValue = "correct value";
+        String wrongValue = "wrong value";
+
+        IIOMetadataNode parent = new IIOMetadataNode("parent");
+        MyAttrNode attrNode1 = new MyAttrNode(name, wrongValue);
+        MyAttrNode attrNode2 = new MyAttrNode(name, correctValue);
+
+        parent.setAttributeNode(attrNode1);
+        parent.setAttributeNode(attrNode2);
+
+        Attr actAttr = parent.getAttributeNode(name);
+        String actValue = actAttr.getValue();
+
+        if (!actValue.equals(correctValue)) {
+            throw new RuntimeException("Test 4 failed: Return value is: " +
+                                       actValue);
+        }
+    }
+
+    public static void main(String[] args) {
+        test1();
+        test2();
+        test3();
+        test4();
+    }
+}
+
+class MyAttrNode extends IIOMetadataNode implements Attr {
+
+    private Element owner;
+    private String name;
+    private String value;
+
+    public MyAttrNode(String name, String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    public Element getOwnerElement() {
+        return owner;
+    }
+
+    public void setOwnerElement(Element owner) {
+        this.owner = owner;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public boolean getSpecified() {
+        return false;
+    }
+
+    public TypeInfo getSchemaTypeInfo() {
+        return null;
+    }
+
+    public boolean isId() {
+        return false;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JMenuItem/6438430/bug6438430.java	Wed Sep 19 12:41:54 2012 -0700
@@ -0,0 +1,76 @@
+/*
+ * 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 6438430
+ * @summary Tests that submenu title doesn't overlap with submenu indicator
+ *          in JPopupMenu
+ * @author Mikhail Lapshin
+ * @run main/othervm -Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel bug6438430
+ * @run main/othervm -Dswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel bug6438430
+ */
+
+import javax.swing.JMenuItem;
+import javax.swing.JMenu;
+import javax.swing.JCheckBoxMenuItem;
+
+public class bug6438430 {
+    public static void main(String[] args) {
+        JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
+        subMenu1.add(new JMenuItem("SubMenu Item"));
+        JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");
+
+        JMenu menu1 = new JMenu("It works always");
+        menu1.add(checkBoxMenuItem1);
+        menu1.add(subMenu1);
+
+        // Simulate DefaultMenuLayout calls.
+        // The latest traversed menu item must be the widest.
+        checkBoxMenuItem1.getPreferredSize();
+        int width1 = subMenu1.getPreferredSize().width;
+        System.out.println("width1 = " + width1);
+
+
+        JMenu subMenu2 = new JMenu("Long-titled Sub Menu");
+        subMenu2.add(new JMenuItem("SubMenu Item"));
+        JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox");
+
+        JMenu menu2 = new JMenu("It did not work before the fix");
+        menu2.add(subMenu2);
+        menu2.add(checkBoxMenuItem2);
+
+        // Simulate DefaultMenuLayout calls.
+        // The latest traversed menu item must be the widest.
+        subMenu2.getPreferredSize();
+        int width2 = checkBoxMenuItem2.getPreferredSize().width;
+        System.out.println("width2 = " + width2);
+
+        if (width1 != width2) {
+            throw new RuntimeException( "Submenu title and submenu indicator " +
+                                        "overlap on JMenuItem!" );
+        }
+
+        System.out.println("Test passed");
+    }
+}