From e3ce03230a650f6350ff13edf64c43a74b3bd27d Mon Sep 17 00:00:00 2001 From: Sean Mullan Date: Wed, 22 Feb 2012 15:38:24 -0500 Subject: [PATCH 001/463] 7145239: Finetune package definition restriction Reviewed-by: hawtin --- jdk/src/share/lib/security/java.security | 6 +++--- jdk/src/share/lib/security/java.security-solaris | 6 +++--- jdk/src/share/lib/security/java.security-windows | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/jdk/src/share/lib/security/java.security b/jdk/src/share/lib/security/java.security index a89d40e194b..1b5518054c3 100644 --- a/jdk/src/share/lib/security/java.security +++ b/jdk/src/share/lib/security/java.security @@ -132,10 +132,10 @@ package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun. # corresponding RuntimePermission ("defineClassInPackage."+package) has # been granted. # -# by default, no packages are restricted for definition, and none of -# the class loaders supplied with the JDK call checkPackageDefinition. +# by default, none of the class loaders supplied with the JDK call +# checkPackageDefinition. # -#package.definition= +package.definition=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio. # # Determines whether this properties file can be appended to diff --git a/jdk/src/share/lib/security/java.security-solaris b/jdk/src/share/lib/security/java.security-solaris index 1a19f44d231..9ec6c64b4b5 100644 --- a/jdk/src/share/lib/security/java.security-solaris +++ b/jdk/src/share/lib/security/java.security-solaris @@ -133,10 +133,10 @@ package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun. # corresponding RuntimePermission ("defineClassInPackage."+package) has # been granted. # -# by default, no packages are restricted for definition, and none of -# the class loaders supplied with the JDK call checkPackageDefinition. +# by default, none of the class loaders supplied with the JDK call +# checkPackageDefinition. # -#package.definition= +package.definition=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio. # # Determines whether this properties file can be appended to diff --git a/jdk/src/share/lib/security/java.security-windows b/jdk/src/share/lib/security/java.security-windows index 3db627a4f32..fbaace84919 100644 --- a/jdk/src/share/lib/security/java.security-windows +++ b/jdk/src/share/lib/security/java.security-windows @@ -133,10 +133,10 @@ package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun. # corresponding RuntimePermission ("defineClassInPackage."+package) has # been granted. # -# by default, no packages are restricted for definition, and none of -# the class loaders supplied with the JDK call checkPackageDefinition. +# by default, none of the class loaders supplied with the JDK call +# checkPackageDefinition. # -#package.definition= +package.definition=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio. # # Determines whether this properties file can be appended to From 39cf6b2fdc8611ddd5a35790f1e833f9d453ff1d Mon Sep 17 00:00:00 2001 From: Andrew Brygin Date: Tue, 28 Feb 2012 10:44:56 +0400 Subject: [PATCH 002/463] 7143617: Improve fontmanager layout lookup operations Reviewed-by: igor, prr, mschoene --- .../native/sun/font/layout/LookupProcessor.cpp | 15 ++++++++++++++- .../native/sun/font/layout/LookupProcessor.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/jdk/src/share/native/sun/font/layout/LookupProcessor.cpp b/jdk/src/share/native/sun/font/layout/LookupProcessor.cpp index eb5002ef8a2..60727aa3f3a 100644 --- a/jdk/src/share/native/sun/font/layout/LookupProcessor.cpp +++ b/jdk/src/share/native/sun/font/layout/LookupProcessor.cpp @@ -95,6 +95,10 @@ le_int32 LookupProcessor::process(LEGlyphStorage &glyphStorage, GlyphPositionAdj if (selectMask != 0) { const LookupTable *lookupTable = lookupListTable->getLookupTable(lookup); + + if (!lookupTable) + continue; + le_uint16 lookupFlags = SWAPW(lookupTable->lookupFlags); glyphIterator.reset(lookupFlags, selectMask); @@ -136,6 +140,9 @@ le_int32 LookupProcessor::selectLookups(const FeatureTable *featureTable, Featur for (le_uint16 lookup = 0; lookup < lookupCount; lookup += 1) { le_uint16 lookupListIndex = SWAPW(featureTable->lookupListIndexArray[lookup]); + if (lookupListIndex >= lookupSelectCount) + continue; + lookupSelectArray[lookupListIndex] |= featureMask; lookupOrderArray[store++] = lookupListIndex; } @@ -147,7 +154,7 @@ LookupProcessor::LookupProcessor(const char *baseAddress, Offset scriptListOffset, Offset featureListOffset, Offset lookupListOffset, LETag scriptTag, LETag languageTag, const FeatureMap *featureMap, le_int32 featureMapCount, le_bool orderFeatures, LEErrorCode& success) - : lookupListTable(NULL), featureListTable(NULL), lookupSelectArray(NULL), + : lookupListTable(NULL), featureListTable(NULL), lookupSelectArray(NULL), lookupSelectCount(0), lookupOrderArray(NULL), lookupOrderCount(0) { const ScriptListTable *scriptListTable = NULL; @@ -195,6 +202,8 @@ LookupProcessor::LookupProcessor(const char *baseAddress, lookupSelectArray[i] = 0; } + lookupSelectCount = lookupListCount; + le_int32 count, order = 0; le_int32 featureReferences = 0; const FeatureTable *featureTable = NULL; @@ -211,6 +220,10 @@ LookupProcessor::LookupProcessor(const char *baseAddress, le_uint16 featureIndex = SWAPW(langSysTable->featureIndexArray[feature]); featureTable = featureListTable->getFeatureTable(featureIndex, &featureTag); + + if (!featureTable) + continue; + featureReferences += SWAPW(featureTable->lookupCount); } diff --git a/jdk/src/share/native/sun/font/layout/LookupProcessor.h b/jdk/src/share/native/sun/font/layout/LookupProcessor.h index 73a44f05cdb..dc474c4f2bc 100644 --- a/jdk/src/share/native/sun/font/layout/LookupProcessor.h +++ b/jdk/src/share/native/sun/font/layout/LookupProcessor.h @@ -90,6 +90,7 @@ protected: const FeatureListTable *featureListTable; FeatureMask *lookupSelectArray; + le_uint32 lookupSelectCount; le_uint16 *lookupOrderArray; le_uint32 lookupOrderCount; From 54c7a4294991fce66e2d921dfd32d075ea616de7 Mon Sep 17 00:00:00 2001 From: Pavel Porvatov Date: Tue, 28 Feb 2012 16:09:15 +0200 Subject: [PATCH 003/463] 7143614: SynthLookAndFeel stability improvement Reviewed-by: malenkov --- .../javax/swing/plaf/synth/SynthButtonUI.java | 4 +- .../javax/swing/plaf/synth/SynthLabelUI.java | 4 +- .../swing/plaf/synth/SynthLookAndFeel.java | 57 ++++++----- .../swing/plaf/synth/7143614/bug7143614.java | 97 +++++++++++++++++++ 4 files changed, 133 insertions(+), 29 deletions(-) create mode 100644 jdk/test/javax/swing/plaf/synth/7143614/bug7143614.java diff --git a/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java b/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java index 80d3eb15fe0..0f5df434c70 100644 --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthButtonUI.java @@ -152,8 +152,8 @@ public class SynthButtonUI extends BasicButtonUI implements if (!c.isEnabled()) { state = DISABLED; } - if (SynthLookAndFeel.selectedUI == this) { - return SynthLookAndFeel.selectedUIState | SynthConstants.ENABLED; + if (SynthLookAndFeel.getSelectedUI() == this) { + return SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED; } AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); diff --git a/jdk/src/share/classes/javax/swing/plaf/synth/SynthLabelUI.java b/jdk/src/share/classes/javax/swing/plaf/synth/SynthLabelUI.java index 1c1927291b8..e0c50e166cd 100644 --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthLabelUI.java +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthLabelUI.java @@ -97,9 +97,9 @@ public class SynthLabelUI extends BasicLabelUI implements SynthUI { private int getComponentState(JComponent c) { int state = SynthLookAndFeel.getComponentState(c); - if (SynthLookAndFeel.selectedUI == this && + if (SynthLookAndFeel.getSelectedUI() == this && state == SynthConstants.ENABLED) { - state = SynthLookAndFeel.selectedUIState | SynthConstants.ENABLED; + state = SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED; } return state; } diff --git a/jdk/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java b/jdk/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java index 12121cc5038..bece289030f 100644 --- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java +++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java @@ -76,28 +76,26 @@ public class SynthLookAndFeel extends BasicLookAndFeel { private static final Object STYLE_FACTORY_KEY = new StringBuffer("com.sun.java.swing.plaf.gtk.StyleCache"); + /** + * AppContext key to get selectedUI. + */ + private static final Object SELECTED_UI_KEY = new StringBuilder("selectedUI"); + + /** + * AppContext key to get selectedUIState. + */ + private static final Object SELECTED_UI_STATE_KEY = new StringBuilder("selectedUIState"); + /** * The last SynthStyleFactory that was asked for from AppContext * lastContext. */ private static SynthStyleFactory lastFactory; - /** - * If this is true it indicates there is more than one AppContext active - * and that we need to make sure in getStyleCache the requesting - * AppContext matches that of lastContext before returning - * it. - */ - private static boolean multipleApps; /** * AppContext lastLAF came from. */ private static AppContext lastContext; - // Refer to setSelectedUI - static ComponentUI selectedUI; - // Refer to setSelectedUI - static int selectedUIState; - /** * SynthStyleFactory for the this SynthLookAndFeel. */ @@ -111,6 +109,10 @@ public class SynthLookAndFeel extends BasicLookAndFeel { private Handler _handler; + static ComponentUI getSelectedUI() { + return (ComponentUI) AppContext.getAppContext().get(SELECTED_UI_KEY); + } + /** * Used by the renderers. For the most part the renderers are implemented * as Labels, which is problematic in so far as they are never selected. @@ -122,8 +124,8 @@ public class SynthLookAndFeel extends BasicLookAndFeel { static void setSelectedUI(ComponentUI uix, boolean selected, boolean focused, boolean enabled, boolean rollover) { - selectedUI = uix; - selectedUIState = 0; + int selectedUIState = 0; + if (selected) { selectedUIState = SynthConstants.SELECTED; if (focused) { @@ -140,19 +142,32 @@ public class SynthLookAndFeel extends BasicLookAndFeel { else { if (enabled) { selectedUIState |= SynthConstants.ENABLED; - selectedUIState = SynthConstants.FOCUSED; + if (focused) { + selectedUIState |= SynthConstants.FOCUSED; + } } else { selectedUIState |= SynthConstants.DISABLED; } } + + AppContext context = AppContext.getAppContext(); + + context.put(SELECTED_UI_KEY, uix); + context.put(SELECTED_UI_STATE_KEY, Integer.valueOf(selectedUIState)); + } + + static int getSelectedUIState() { + Integer result = (Integer) AppContext.getAppContext().get(SELECTED_UI_STATE_KEY); + + return result == null ? 0 : result.intValue(); } /** * Clears out the selected UI that was last set in setSelectedUI. */ static void resetSelectedUI() { - selectedUI = null; + AppContext.getAppContext().remove(SELECTED_UI_KEY); } @@ -167,10 +182,6 @@ public class SynthLookAndFeel extends BasicLookAndFeel { // for a particular AppContext. synchronized(SynthLookAndFeel.class) { AppContext context = AppContext.getAppContext(); - if (!multipleApps && context != lastContext && - lastContext != null) { - multipleApps = true; - } lastFactory = cache; lastContext = context; context.put(STYLE_FACTORY_KEY, cache); @@ -184,17 +195,13 @@ public class SynthLookAndFeel extends BasicLookAndFeel { */ public static SynthStyleFactory getStyleFactory() { synchronized(SynthLookAndFeel.class) { - if (!multipleApps) { - return lastFactory; - } AppContext context = AppContext.getAppContext(); if (lastContext == context) { return lastFactory; } lastContext = context; - lastFactory = (SynthStyleFactory)AppContext.getAppContext().get - (STYLE_FACTORY_KEY); + lastFactory = (SynthStyleFactory) context.get(STYLE_FACTORY_KEY); return lastFactory; } } diff --git a/jdk/test/javax/swing/plaf/synth/7143614/bug7143614.java b/jdk/test/javax/swing/plaf/synth/7143614/bug7143614.java new file mode 100644 index 00000000000..a4f81fd031e --- /dev/null +++ b/jdk/test/javax/swing/plaf/synth/7143614/bug7143614.java @@ -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 7143614 + * @summary Issues with Synth Look&Feel + * @author Pavel Porvatov + */ + +import sun.awt.SunToolkit; + +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicButtonUI; +import javax.swing.plaf.synth.SynthConstants; +import javax.swing.plaf.synth.SynthLookAndFeel; +import java.lang.reflect.Method; + +public class bug7143614 { + private static Method setSelectedUIMethod; + + private static ComponentUI componentUI = new BasicButtonUI(); + + public static void main(String[] args) throws Exception { + setSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("setSelectedUI", ComponentUI.class, + boolean.class, boolean.class, boolean.class, boolean.class); + setSelectedUIMethod.setAccessible(true); + + setSelectedUIMethod.invoke(null, componentUI, true, true, true, true); + + validate(); + + Thread thread = new ThreadInAnotherAppContext(); + + thread.start(); + thread.join(); + + validate(); + + System.out.println("Test bug7143614 passed."); + } + + private static void validate() throws Exception { + Method getSelectedUIMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUI"); + + getSelectedUIMethod.setAccessible(true); + + Method getSelectedUIStateMethod = SynthLookAndFeel.class.getDeclaredMethod("getSelectedUIState"); + + getSelectedUIStateMethod.setAccessible(true); + + if (getSelectedUIMethod.invoke(null) != componentUI) { + throw new RuntimeException("getSelectedUI returns invalid value"); + } + if (((Integer) getSelectedUIStateMethod.invoke(null)).intValue() != + (SynthConstants.SELECTED | SynthConstants.FOCUSED)) { + throw new RuntimeException("getSelectedUIState returns invalid value"); + } + + } + + private static class ThreadInAnotherAppContext extends Thread { + public ThreadInAnotherAppContext() { + super(new ThreadGroup("7143614"), "ThreadInAnotherAppContext"); + } + + public void run() { + SunToolkit.createNewAppContext(); + + try { + setSelectedUIMethod.invoke(null, null, false, false, false, false); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } +} From 7902f129f5a45a71f9af2ee7c03e7c2d96eb0ac2 Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Wed, 29 Feb 2012 14:06:00 +0800 Subject: [PATCH 004/463] 7143872: Improve certificate extension processing Reviewed-by: mullan --- .../sun/security/x509/CRLExtensions.java | 9 +- .../security/x509/CertificateExtensions.java | 13 ++- .../sun/security/x509/X509CRLEntryImpl.java | 52 +++++++--- .../sun/security/x509/X509CRLImpl.java | 56 ++++++----- .../sun/security/x509/X509CertImpl.java | 22 +++-- .../x509/X509CRLImpl/OrderAndDup.java | 99 +++++++++++++++++++ 6 files changed, 201 insertions(+), 50 deletions(-) create mode 100644 jdk/test/sun/security/x509/X509CRLImpl/OrderAndDup.java diff --git a/jdk/src/share/classes/sun/security/x509/CRLExtensions.java b/jdk/src/share/classes/sun/security/x509/CRLExtensions.java index 7b6c34b54a0..dc1fc71968c 100644 --- a/jdk/src/share/classes/sun/security/x509/CRLExtensions.java +++ b/jdk/src/share/classes/sun/security/x509/CRLExtensions.java @@ -32,8 +32,10 @@ import java.lang.reflect.InvocationTargetException; import java.security.cert.CRLException; import java.security.cert.CertificateException; import java.util.Collection; +import java.util.Collections; import java.util.Enumeration; -import java.util.Hashtable; +import java.util.Map; +import java.util.TreeMap; import sun.security.util.*; import sun.misc.HexDumpEncoder; @@ -62,7 +64,8 @@ import sun.misc.HexDumpEncoder; */ public class CRLExtensions { - private Hashtable map = new Hashtable(); + private Map map = Collections.synchronizedMap( + new TreeMap()); private boolean unsupportedCritExt = false; /** @@ -215,7 +218,7 @@ public class CRLExtensions { * @return an enumeration of the extensions in this CRL. */ public Enumeration getElements() { - return map.elements(); + return Collections.enumeration(map.values()); } /** diff --git a/jdk/src/share/classes/sun/security/x509/CertificateExtensions.java b/jdk/src/share/classes/sun/security/x509/CertificateExtensions.java index b1dc9367512..65dcff1a3e1 100644 --- a/jdk/src/share/classes/sun/security/x509/CertificateExtensions.java +++ b/jdk/src/share/classes/sun/security/x509/CertificateExtensions.java @@ -57,7 +57,8 @@ public class CertificateExtensions implements CertAttrSet { private static final Debug debug = Debug.getInstance("x509"); - private Hashtable map = new Hashtable(); + private Map map = Collections.synchronizedMap( + new TreeMap()); private boolean unsupportedCritExt = false; private Map unparseableExtensions; @@ -117,7 +118,7 @@ public class CertificateExtensions implements CertAttrSet { if (ext.isCritical() == false) { // ignore errors parsing non-critical extensions if (unparseableExtensions == null) { - unparseableExtensions = new HashMap(); + unparseableExtensions = new TreeMap(); } unparseableExtensions.put(ext.getExtensionId().toString(), new UnparseableExtension(ext, e)); @@ -218,6 +219,12 @@ public class CertificateExtensions implements CertAttrSet { return (obj); } + // Similar to get(String), but throw no exception, might return null. + // Used in X509CertImpl::getExtension(OID). + Extension getExtension(String name) { + return map.get(name); + } + /** * Delete the attribute value. * @param name the extension name used in the lookup. @@ -245,7 +252,7 @@ public class CertificateExtensions implements CertAttrSet { * attribute. */ public Enumeration getElements() { - return map.elements(); + return Collections.enumeration(map.values()); } /** diff --git a/jdk/src/share/classes/sun/security/x509/X509CRLEntryImpl.java b/jdk/src/share/classes/sun/security/x509/X509CRLEntryImpl.java index 495cc06e5be..a074c38720b 100644 --- a/jdk/src/share/classes/sun/security/x509/X509CRLEntryImpl.java +++ b/jdk/src/share/classes/sun/security/x509/X509CRLEntryImpl.java @@ -32,13 +32,7 @@ import java.security.cert.CRLReason; import java.security.cert.CertificateException; import java.security.cert.X509CRLEntry; import java.math.BigInteger; -import java.util.Collection; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.HashSet; +import java.util.*; import javax.security.auth.x500.X500Principal; @@ -75,7 +69,8 @@ import sun.misc.HexDumpEncoder; * @author Hemma Prafullchandra */ -public class X509CRLEntryImpl extends X509CRLEntry { +public class X509CRLEntryImpl extends X509CRLEntry + implements Comparable { private SerialNumber serialNumber = null; private Date revocationDate = null; @@ -196,9 +191,14 @@ public class X509CRLEntryImpl extends X509CRLEntry { * @exception CRLException if an encoding error occurs. */ public byte[] getEncoded() throws CRLException { + return getEncoded0().clone(); + } + + // Called internally to avoid clone + private byte[] getEncoded0() throws CRLException { if (revokedCert == null) this.encode(new DerOutputStream()); - return revokedCert.clone(); + return revokedCert; } @Override @@ -352,7 +352,7 @@ public class X509CRLEntryImpl extends X509CRLEntry { if (extensions == null) { return null; } - Set extSet = new HashSet(); + Set extSet = new TreeSet<>(); for (Extension ex : extensions.getAllExtensions()) { if (ex.isCritical()) { extSet.add(ex.getExtensionId().toString()); @@ -373,7 +373,7 @@ public class X509CRLEntryImpl extends X509CRLEntry { if (extensions == null) { return null; } - Set extSet = new HashSet(); + Set extSet = new TreeSet<>(); for (Extension ex : extensions.getAllExtensions()) { if (!ex.isCritical()) { extSet.add(ex.getExtensionId().toString()); @@ -501,13 +501,39 @@ public class X509CRLEntryImpl extends X509CRLEntry { getExtension(PKIXExtensions.CertificateIssuer_Id); } + /** + * Returns all extensions for this entry in a map + * @return the extension map, can be empty, but not null + */ public Map getExtensions() { + if (extensions == null) { + return Collections.emptyMap(); + } Collection exts = extensions.getAllExtensions(); - HashMap map = - new HashMap(exts.size()); + Map map = new TreeMap<>(); for (Extension ext : exts) { map.put(ext.getId(), ext); } return map; } + + @Override + public int compareTo(X509CRLEntryImpl that) { + int compSerial = getSerialNumber().compareTo(that.getSerialNumber()); + if (compSerial != 0) { + return compSerial; + } + try { + byte[] thisEncoded = this.getEncoded0(); + byte[] thatEncoded = that.getEncoded0(); + for (int i=0; i - * An implmentation for X509 CRL (Certificate Revocation List). + * An implementation for X509 CRL (Certificate Revocation List). *

* The X.509 v2 CRL format is described below in ASN.1: *

@@ -104,7 +104,8 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
     private X500Principal    issuerPrincipal = null;
     private Date             thisUpdate = null;
     private Date             nextUpdate = null;
-    private Map revokedCerts = new LinkedHashMap();
+    private Map revokedMap = new TreeMap<>();
+    private List revokedList = new LinkedList<>();
     private CRLExtensions    extensions = null;
     private final static boolean isExplicit = true;
     private static final long YR_2050 = 2524636800000L;
@@ -223,7 +224,8 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
                 badCert.setCertificateIssuer(crlIssuer, badCertIssuer);
                 X509IssuerSerial issuerSerial = new X509IssuerSerial
                     (badCertIssuer, badCert.getSerialNumber());
-                this.revokedCerts.put(issuerSerial, badCert);
+                this.revokedMap.put(issuerSerial, badCert);
+                this.revokedList.add(badCert);
                 if (badCert.hasExtensions()) {
                     this.version = 1;
                 }
@@ -305,8 +307,8 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
                     tmp.putGeneralizedTime(nextUpdate);
             }
 
-            if (!revokedCerts.isEmpty()) {
-                for (X509CRLEntry entry : revokedCerts.values()) {
+            if (!revokedList.isEmpty()) {
+                for (X509CRLEntry entry : revokedList) {
                     ((X509CRLEntryImpl)entry).encode(rCerts);
                 }
                 tmp.write(DerValue.tag_Sequence, rCerts);
@@ -490,14 +492,14 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
             sb.append("\nThis Update: " + thisUpdate.toString() + "\n");
         if (nextUpdate != null)
             sb.append("Next Update: " + nextUpdate.toString() + "\n");
-        if (revokedCerts.isEmpty())
+        if (revokedList.isEmpty())
             sb.append("\nNO certificates have been revoked\n");
         else {
-            sb.append("\nRevoked Certificates: " + revokedCerts.size());
+            sb.append("\nRevoked Certificates: " + revokedList.size());
             int i = 1;
-            for (Iterator iter = revokedCerts.values().iterator();
-                                             iter.hasNext(); i++)
-                sb.append("\n[" + i + "] " + iter.next().toString());
+            for (X509CRLEntry entry: revokedList) {
+                sb.append("\n[" + i++ + "] " + entry.toString());
+            }
         }
         if (extensions != null) {
             Collection allExts = extensions.getAllExtensions();
@@ -543,12 +545,12 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
      * false otherwise.
      */
     public boolean isRevoked(Certificate cert) {
-        if (revokedCerts.isEmpty() || (!(cert instanceof X509Certificate))) {
+        if (revokedMap.isEmpty() || (!(cert instanceof X509Certificate))) {
             return false;
         }
         X509Certificate xcert = (X509Certificate) cert;
         X509IssuerSerial issuerSerial = new X509IssuerSerial(xcert);
-        return revokedCerts.containsKey(issuerSerial);
+        return revokedMap.containsKey(issuerSerial);
     }
 
     /**
@@ -638,24 +640,24 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
      * @see X509CRLEntry
      */
     public X509CRLEntry getRevokedCertificate(BigInteger serialNumber) {
-        if (revokedCerts.isEmpty()) {
+        if (revokedMap.isEmpty()) {
             return null;
         }
         // assume this is a direct CRL entry (cert and CRL issuer are the same)
         X509IssuerSerial issuerSerial = new X509IssuerSerial
             (getIssuerX500Principal(), serialNumber);
-        return revokedCerts.get(issuerSerial);
+        return revokedMap.get(issuerSerial);
     }
 
     /**
      * Gets the CRL entry for the given certificate.
      */
     public X509CRLEntry getRevokedCertificate(X509Certificate cert) {
-        if (revokedCerts.isEmpty()) {
+        if (revokedMap.isEmpty()) {
             return null;
         }
         X509IssuerSerial issuerSerial = new X509IssuerSerial(cert);
-        return revokedCerts.get(issuerSerial);
+        return revokedMap.get(issuerSerial);
     }
 
     /**
@@ -667,10 +669,10 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
      * @see X509CRLEntry
      */
     public Set getRevokedCertificates() {
-        if (revokedCerts.isEmpty()) {
+        if (revokedList.isEmpty()) {
             return null;
         } else {
-            return new HashSet(revokedCerts.values());
+            return new TreeSet(revokedList);
         }
     }
 
@@ -905,7 +907,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
         if (extensions == null) {
             return null;
         }
-        Set extSet = new HashSet();
+        Set extSet = new TreeSet<>();
         for (Extension ex : extensions.getAllExtensions()) {
             if (ex.isCritical()) {
                 extSet.add(ex.getExtensionId().toString());
@@ -926,7 +928,7 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
         if (extensions == null) {
             return null;
         }
-        Set extSet = new HashSet();
+        Set extSet = new TreeSet<>();
         for (Extension ex : extensions.getAllExtensions()) {
             if (!ex.isCritical()) {
                 extSet.add(ex.getExtensionId().toString());
@@ -1103,7 +1105,8 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
                 entry.setCertificateIssuer(crlIssuer, badCertIssuer);
                 X509IssuerSerial issuerSerial = new X509IssuerSerial
                     (badCertIssuer, entry.getSerialNumber());
-                revokedCerts.put(issuerSerial, entry);
+                revokedMap.put(issuerSerial, entry);
+                revokedList.add(entry);
             }
         }
 
@@ -1208,7 +1211,8 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
     /**
      * Immutable X.509 Certificate Issuer DN and serial number pair
      */
-    private final static class X509IssuerSerial {
+    private final static class X509IssuerSerial
+            implements Comparable {
         final X500Principal issuer;
         final BigInteger serial;
         volatile int hashcode = 0;
@@ -1287,5 +1291,13 @@ public class X509CRLImpl extends X509CRL implements DerEncoder {
             }
             return hashcode;
         }
+
+        @Override
+        public int compareTo(X509IssuerSerial another) {
+            int cissuer = issuer.toString()
+                    .compareTo(another.issuer.toString());
+            if (cissuer != 0) return cissuer;
+            return this.serial.compareTo(another.serial);
+        }
     }
 }
diff --git a/jdk/src/share/classes/sun/security/x509/X509CertImpl.java b/jdk/src/share/classes/sun/security/x509/X509CertImpl.java
index eb7dc39c0bf..64ac1c36176 100644
--- a/jdk/src/share/classes/sun/security/x509/X509CertImpl.java
+++ b/jdk/src/share/classes/sun/security/x509/X509CertImpl.java
@@ -1214,7 +1214,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
             if (exts == null) {
                 return null;
             }
-            Set extSet = new HashSet();
+            Set extSet = new TreeSet<>();
             for (Extension ex : exts.getAllExtensions()) {
                 if (ex.isCritical()) {
                     extSet.add(ex.getExtensionId().toString());
@@ -1244,7 +1244,7 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
             if (exts == null) {
                 return null;
             }
-            Set extSet = new HashSet();
+            Set extSet = new TreeSet<>();
             for (Extension ex : exts.getAllExtensions()) {
                 if (!ex.isCritical()) {
                     extSet.add(ex.getExtensionId().toString());
@@ -1278,10 +1278,14 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
             if (extensions == null) {
                 return null;
             } else {
-                for (Extension ex : extensions.getAllExtensions()) {
-                    if (ex.getExtensionId().equals(oid)) {
+                Extension ex = extensions.getExtension(oid.toString());
+                if (ex != null) {
+                    return ex;
+                }
+                for (Extension ex2: extensions.getAllExtensions()) {
+                    if (ex2.getExtensionId().equals((Object)oid)) {
                         //XXXX May want to consider cloning this
-                        return ex;
+                        return ex2;
                     }
                 }
                 /* no such extension in this certificate */
@@ -1480,10 +1484,10 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
         if (names.isEmpty()) {
             return Collections.>emptySet();
         }
-        Set> newNames = new HashSet>();
+        List> newNames = new ArrayList<>();
         for (GeneralName gname : names.names()) {
             GeneralNameInterface name = gname.getName();
-            List nameEntry = new ArrayList(2);
+            List nameEntry = new ArrayList<>(2);
             nameEntry.add(Integer.valueOf(name.getType()));
             switch (name.getType()) {
             case GeneralNameInterface.NAME_RFC822:
@@ -1541,12 +1545,12 @@ public class X509CertImpl extends X509Certificate implements DerEncoder {
             }
         }
         if (mustClone) {
-            Set> namesCopy = new HashSet>();
+            List> namesCopy = new ArrayList<>();
             for (List nameEntry : altNames) {
                 Object nameObject = nameEntry.get(1);
                 if (nameObject instanceof byte[]) {
                     List nameEntryCopy =
-                                        new ArrayList(nameEntry);
+                                        new ArrayList<>(nameEntry);
                     nameEntryCopy.set(1, ((byte[])nameObject).clone());
                     namesCopy.add(Collections.unmodifiableList(nameEntryCopy));
                 } else {
diff --git a/jdk/test/sun/security/x509/X509CRLImpl/OrderAndDup.java b/jdk/test/sun/security/x509/X509CRLImpl/OrderAndDup.java
new file mode 100644
index 00000000000..51610e61c7f
--- /dev/null
+++ b/jdk/test/sun/security/x509/X509CRLImpl/OrderAndDup.java
@@ -0,0 +1,99 @@
+/*
+ * 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 7143872
+ * @summary Improve certificate extension processing
+ */
+import java.io.ByteArrayInputStream;
+import java.math.BigInteger;
+import java.security.KeyPairGenerator;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509CRLEntry;
+import java.util.Date;
+import sun.security.util.DerInputStream;
+import sun.security.util.DerValue;
+import sun.security.x509.*;
+
+public class OrderAndDup {
+    public static void main(String[] args) throws Exception {
+
+        // Generate 20 serial numbers with dup and a special order
+        int count = 20;
+        BigInteger[] serials = new BigInteger[count];
+        for (int i=0; i
Date: Mon, 26 Mar 2012 14:01:40 +0100
Subject: [PATCH 005/463] 7143851: Improve IIOP stub and tie generation in RMIC
 7149048: Changes to corba rmic stubGenerator class are not used during jdk
 build process

Reviewed-by: mschoene, robm
---
 .../share/classes/sun/rmi/rmic/iiop/StubGenerator.java    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/corba/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java b/corba/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java
index 87eee7bef61..143beefc8e1 100644
--- a/corba/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java
+++ b/corba/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -425,7 +425,7 @@ public class StubGenerator extends sun.rmi.rmic.iiop.Generator {
         // Write the _ids() method...
 
         p.plnI("public String[] _ids() { ");
-        p.pln("return _type_ids;");
+        p.pln("return (String[]) _type_ids.clone();");
         p.pOln("}");
 
         // Get all the methods and write each stub method...
@@ -1860,11 +1860,11 @@ public class StubGenerator extends sun.rmi.rmic.iiop.Generator {
     {
         if(POATie){
         p.plnI("public String[] _all_interfaces(org.omg.PortableServer.POA poa, byte[] objectId){");
-        p.pln("return _type_ids;");
+        p.pln("return (String[]) _type_ids.clone();");
         p.pOln("}");
         } else {
         p.plnI("public String[] _ids() { ");
-        p.pln("return _type_ids;");
+        p.pln("return (String[]) _type_ids.clone();");
         p.pOln("}");
         }
     }

From 502876ad9aa02790e3a36e3e827a9904c97cd2eb Mon Sep 17 00:00:00 2001
From: Sean Coffey 
Date: Mon, 26 Mar 2012 14:03:09 +0100
Subject: [PATCH 006/463] 7143851: Improve IIOP stub and tie generation in RMIC
 7149048: Changes to corba rmic stubGenerator class are not used during jdk
 build process

Reviewed-by: mschoene, robm
---
 jdk/make/com/sun/jmx/Makefile | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/jdk/make/com/sun/jmx/Makefile b/jdk/make/com/sun/jmx/Makefile
index 2f036de3576..62435751673 100644
--- a/jdk/make/com/sun/jmx/Makefile
+++ b/jdk/make/com/sun/jmx/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2003, 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
@@ -100,6 +100,23 @@ FILES_ties   = $(subst javax/management/remote/rmi/,javax/management/remote/rmi/
 # so that *_tie classes are generated in package without the prefix
 # org.omg.stub (6375696)
 # 
+# To ensure the latest stub generator files are picked up from corba repo
+# when available, we need to run with latest rmic version available. rmic 
+# launch tool not built at this stage but we can invoke via rmi class.
+
+RMIC_JAVA = $(OUTPUTDIR)/bin/java
+# need to treat 64bit solaris differently
+ifeq ($(PLATFORM)-$(LIBARCH), solaris-amd64)
+RMIC_JAVA = $(OUTPUTDIR)/bin/amd64/java
+endif
+ifeq ($(PLATFORM)-$(LIBARCH), solaris-sparcv9)
+RMIC_JAVA = $(OUTPUTDIR)/bin/sparcv9/java
+endif
+
+ifeq ($(CROSS_COMPILE_ARCH),)
+RMIC = $(RMIC_JAVA) $(JAVA_TOOLS_FLAGS) -cp $(OUTPUTDIR)/classes sun.rmi.rmic.Main
+endif  
+
 $(CLASSDESTDIR)/%_Stub.class: $(CLASSDESTDIR)/%.class
 	$(prep-target)
 	$(RMIC) -classpath "$(CLASSDESTDIR)"    \

From 7709928453eced124160215a4b4774e001d29f68 Mon Sep 17 00:00:00 2001
From: Mala Bankal 
Date: Wed, 28 Mar 2012 02:50:50 -0700
Subject: [PATCH 007/463] 7079902: Refine CORBA data models

Reviewed-by: coffeys
---
 .../interceptors/ClientRequestInfoImpl.java   |  4 +--
 .../interceptors/ServerRequestInfoImpl.java   |  4 +--
 .../corba/se/impl/javax/rmi/CORBA/Util.java   | 19 +++++++++--
 .../impl/oa/poa/POAPolicyMediatorBase_R.java  |  6 ++--
 .../sun/corba/se/impl/oa/toa/TOAFactory.java  |  6 ++--
 .../sun/corba/se/impl/orb/ParserTable.java    |  6 ++--
 .../se/impl/orbutil/RepositoryId_1_3.java     | 18 +++++-----
 .../se/impl/orbutil/RepositoryId_1_3_1.java   | 18 +++++-----
 .../LocalClientRequestDispatcherBase.java     |  4 +--
 .../sun/corba/se/impl/util/RepositoryId.java  | 20 +++++------
 .../corba/se/spi/logging/CORBALogDomains.java |  4 +--
 .../classes/sun/rmi/rmic/iiop/IDLNames.java   | 34 +++++++++++++++++--
 12 files changed, 93 insertions(+), 50 deletions(-)

diff --git a/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ClientRequestInfoImpl.java b/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ClientRequestInfoImpl.java
index d24fa030725..94e3f957c31 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ClientRequestInfoImpl.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ClientRequestInfoImpl.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -217,7 +217,7 @@ public final class ClientRequestInfoImpl
 
     // ClientRequestInfo validity table (see ptc/00-08-06 table 21-1).
     // Note: These must be in the same order as specified in contants.
-    protected static final boolean validCall[][] = {
+    private static final boolean validCall[][] = {
         // LEGEND:
         // s_req = send_request     r_rep = receive_reply
         // s_pol = send_poll        r_exc = receive_exception
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ServerRequestInfoImpl.java b/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ServerRequestInfoImpl.java
index 4df8825d0bb..ecea44c521b 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ServerRequestInfoImpl.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/interceptors/ServerRequestInfoImpl.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -195,7 +195,7 @@ public final class ServerRequestInfoImpl
 
     // ServerRequestInfo validity table (see ptc/00-08-06 table 21-2).
     // Note: These must be in the same order as specified in contants.
-    protected static final boolean validCall[][] = {
+    private static final boolean validCall[][] = {
         // LEGEND:
         // r_rsc = receive_request_service_contexts
         // r_req = receive_request
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java b/corba/src/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java
index 6653b391c46..7721999591c 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2004, 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
@@ -130,10 +130,23 @@ public class Util implements javax.rmi.CORBA.UtilDelegate
     private UtilSystemException utilWrapper = UtilSystemException.get(
                                                   CORBALogDomains.RPC_ENCODING);
 
-    public static Util instance = null;
+    private static Util instance = null;
 
     public Util() {
-        instance = this;
+        setInstance(this);
+    }
+
+    private static void setInstance( Util util ) {
+        assert instance == null : "Instance already defined";
+        instance = util;
+    }
+
+    public static Util getInstance() {
+        return instance;
+    }
+
+    public static boolean isInstanceDefined() {
+        return instance != null;
     }
 
     // Used by TOAFactory.shutdown to unexport all targets for this
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorBase_R.java b/corba/src/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorBase_R.java
index 1bc9130e109..3b14616947a 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorBase_R.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/oa/poa/POAPolicyMediatorBase_R.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -93,7 +93,7 @@ public abstract class POAPolicyMediatorBase_R extends POAPolicyMediatorBase {
 
         activeObjectMap.putServant( servant, entry ) ;
 
-        if (Util.instance != null) {
+        if (Util.isInstanceDefined()) {
             POAManagerImpl pm = (POAManagerImpl)poa.the_POAManager() ;
             POAFactory factory = pm.getFactory() ;
             factory.registerPOAForServant(poa, servant);
@@ -129,7 +129,7 @@ public abstract class POAPolicyMediatorBase_R extends POAPolicyMediatorBase {
 
         activeObjectMap.remove(key);
 
-        if (Util.instance != null) {
+        if (Util.isInstanceDefined()) {
             POAManagerImpl pm = (POAManagerImpl)poa.the_POAManager() ;
             POAFactory factory = pm.getFactory() ;
             factory.unregisterPOAForServant(poa, s);
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/oa/toa/TOAFactory.java b/corba/src/share/classes/com/sun/corba/se/impl/oa/toa/TOAFactory.java
index 2a2114d709e..58823229069 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/oa/toa/TOAFactory.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/oa/toa/TOAFactory.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -78,8 +78,8 @@ public class TOAFactory implements ObjectAdapterFactory
 
     public void shutdown( boolean waitForCompletion )
     {
-        if (Util.instance != null) {
-            Util.instance.unregisterTargetsForORB(orb);
+        if (Util.isInstanceDefined()) {
+            Util.getInstance().unregisterTargetsForORB(orb);
         }
     }
 
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/orb/ParserTable.java b/corba/src/share/classes/com/sun/corba/se/impl/orb/ParserTable.java
index 2741e0b29b7..550c4a7f304 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/orb/ParserTable.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/orb/ParserTable.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -106,7 +106,9 @@ public class ParserTable {
 
     public ParserData[] getParserData()
     {
-        return parserData ;
+        ParserData[] parserArray = new ParserData[parserData.length];
+        System.arraycopy(parserData, 0, parserArray, 0, parserData.length);
+        return parserArray;
     }
 
     private ParserTable() {
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3.java b/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3.java
index c2e0995092d..8cf9edd4834 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -62,7 +62,7 @@ public class RepositoryId_1_3 {
     // legal use of '.' in a Java name.
 
     public static final RepositoryIdCache_1_3 cache = new RepositoryIdCache_1_3();
-    public static final byte[] IDL_IDENTIFIER_CHARS = {
+    private static final byte[] IDL_IDENTIFIER_CHARS = {
 
         // 0 1 2 3  4 5 6 7  8 9 a b  c d e f
         0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f
@@ -180,7 +180,7 @@ public class RepositoryId_1_3 {
     public static final String kRemoteTypeStr = "";
     public static final String kRemoteValueRepID = "";
 
-    public static final Hashtable kSpecialArrayTypeStrings = new Hashtable();
+    private static final Hashtable kSpecialArrayTypeStrings = new Hashtable();
 
     static {
         kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName()));
@@ -189,7 +189,7 @@ public class RepositoryId_1_3 {
 
     }
 
-    public static final Hashtable kSpecialCasesRepIDs = new Hashtable();
+    private static final Hashtable kSpecialCasesRepIDs = new Hashtable();
 
     static {
         kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID);
@@ -197,7 +197,7 @@ public class RepositoryId_1_3 {
         kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID);
     }
 
-    public static final Hashtable kSpecialCasesStubValues = new Hashtable();
+    private static final Hashtable kSpecialCasesStubValues = new Hashtable();
 
     static {
         kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue);
@@ -209,7 +209,7 @@ public class RepositoryId_1_3 {
     }
 
 
-    public static final Hashtable kSpecialCasesVersions = new Hashtable();
+    private static final Hashtable kSpecialCasesVersions = new Hashtable();
 
     static {
         kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash);
@@ -220,7 +220,7 @@ public class RepositoryId_1_3 {
         kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash);
     }
 
-    public static final Hashtable kSpecialCasesClasses = new Hashtable();
+    private static final Hashtable kSpecialCasesClasses = new Hashtable();
 
     static {
         kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class);
@@ -232,7 +232,7 @@ public class RepositoryId_1_3 {
         //kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class);
     }
 
-    public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable();
+    private static final Hashtable kSpecialCasesArrayPrefix = new Hashtable();
 
     static {
         kSpecialCasesArrayPrefix.put(java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
@@ -243,7 +243,7 @@ public class RepositoryId_1_3 {
         kSpecialCasesArrayPrefix.put(java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
     }
 
-    public static final Hashtable kSpecialPrimitives = new Hashtable();
+    private static final Hashtable kSpecialPrimitives = new Hashtable();
 
     static {
         kSpecialPrimitives.put("int","long");
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3_1.java b/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3_1.java
index 9ff74e3168a..8c1ab6e7390 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3_1.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/orbutil/RepositoryId_1_3_1.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -63,7 +63,7 @@ public class RepositoryId_1_3_1 {
     // uniformly, and is safe because that is the only
     // legal use of '.' in a Java name.
 
-    public static final byte[] IDL_IDENTIFIER_CHARS = {
+    private static final byte[] IDL_IDENTIFIER_CHARS = {
 
         // 0 1 2 3  4 5 6 7  8 9 a b  c d e f
         0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f
@@ -198,7 +198,7 @@ public class RepositoryId_1_3_1 {
     public static final String kRemoteTypeStr = "";
     public static final String kRemoteValueRepID = "";
 
-    public static final Hashtable kSpecialArrayTypeStrings = new Hashtable();
+    private static final Hashtable kSpecialArrayTypeStrings = new Hashtable();
 
     static {
         kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName()));
@@ -207,7 +207,7 @@ public class RepositoryId_1_3_1 {
 
     }
 
-    public static final Hashtable kSpecialCasesRepIDs = new Hashtable();
+    private static final Hashtable kSpecialCasesRepIDs = new Hashtable();
 
     static {
         kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID);
@@ -215,7 +215,7 @@ public class RepositoryId_1_3_1 {
         kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID);
     }
 
-    public static final Hashtable kSpecialCasesStubValues = new Hashtable();
+    private static final Hashtable kSpecialCasesStubValues = new Hashtable();
 
     static {
         kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue);
@@ -227,7 +227,7 @@ public class RepositoryId_1_3_1 {
     }
 
 
-    public static final Hashtable kSpecialCasesVersions = new Hashtable();
+    private static final Hashtable kSpecialCasesVersions = new Hashtable();
 
     static {
         kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash);
@@ -238,7 +238,7 @@ public class RepositoryId_1_3_1 {
         kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash);
     }
 
-    public static final Hashtable kSpecialCasesClasses = new Hashtable();
+    private static final Hashtable kSpecialCasesClasses = new Hashtable();
 
     static {
         kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class);
@@ -250,7 +250,7 @@ public class RepositoryId_1_3_1 {
         //kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class);
     }
 
-    public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable();
+    private static final Hashtable kSpecialCasesArrayPrefix = new Hashtable();
 
     static {
         kSpecialCasesArrayPrefix.put(java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
@@ -261,7 +261,7 @@ public class RepositoryId_1_3_1 {
         kSpecialCasesArrayPrefix.put(java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
     }
 
-    public static final Hashtable kSpecialPrimitives = new Hashtable();
+    private static final Hashtable kSpecialPrimitives = new Hashtable();
 
     static {
         kSpecialPrimitives.put("int","long");
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/protocol/LocalClientRequestDispatcherBase.java b/corba/src/share/classes/com/sun/corba/se/impl/protocol/LocalClientRequestDispatcherBase.java
index 03e06439060..627ca7abd89 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/protocol/LocalClientRequestDispatcherBase.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/protocol/LocalClientRequestDispatcherBase.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -52,7 +52,7 @@ public abstract class LocalClientRequestDispatcherBase implements LocalClientReq
 
     // If isNextIsLocalValid.get() == Boolean.TRUE,
     // the next call to isLocal should be valid
-    protected static ThreadLocal isNextCallValid = new ThreadLocal() {
+    private static final ThreadLocal isNextCallValid = new ThreadLocal() {
             protected synchronized Object initialValue() {
                 return Boolean.TRUE;
             }
diff --git a/corba/src/share/classes/com/sun/corba/se/impl/util/RepositoryId.java b/corba/src/share/classes/com/sun/corba/se/impl/util/RepositoryId.java
index 7c17e4f63e0..6bedab382ea 100644
--- a/corba/src/share/classes/com/sun/corba/se/impl/util/RepositoryId.java
+++ b/corba/src/share/classes/com/sun/corba/se/impl/util/RepositoryId.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -57,7 +57,7 @@ public class RepositoryId {
     // uniformly, and is safe because that is the only
     // legal use of '.' in a Java name.
 
-    public static final byte[] IDL_IDENTIFIER_CHARS = {
+    private static final byte[] IDL_IDENTIFIER_CHARS = {
 
         // 0 1 2 3  4 5 6 7  8 9 a b  c d e f
         0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f
@@ -95,7 +95,7 @@ public class RepositoryId {
     private static IdentityHashtable classIDLToRepStr = new IdentityHashtable();
     private static IdentityHashtable classSeqToRepStr = new IdentityHashtable();
 
-    private static IdentityHashtable repStrToByteArray = new IdentityHashtable();
+    private static final IdentityHashtable repStrToByteArray = new IdentityHashtable();
     private static Hashtable repStrToClass = new Hashtable();
 
     private String repId = null;
@@ -192,7 +192,7 @@ public class RepositoryId {
     public static final String kRemoteTypeStr = "";
     public static final String kRemoteValueRepID = "";
 
-    public static final Hashtable kSpecialArrayTypeStrings = new Hashtable();
+    private static final Hashtable kSpecialArrayTypeStrings = new Hashtable();
 
     static {
         kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName()));
@@ -201,7 +201,7 @@ public class RepositoryId {
 
     }
 
-    public static final Hashtable kSpecialCasesRepIDs = new Hashtable();
+    private static final Hashtable kSpecialCasesRepIDs = new Hashtable();
 
     static {
         kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID);
@@ -209,7 +209,7 @@ public class RepositoryId {
         kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID);
     }
 
-    public static final Hashtable kSpecialCasesStubValues = new Hashtable();
+    private static final Hashtable kSpecialCasesStubValues = new Hashtable();
 
     static {
         kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue);
@@ -221,7 +221,7 @@ public class RepositoryId {
     }
 
 
-    public static final Hashtable kSpecialCasesVersions = new Hashtable();
+    private static final Hashtable kSpecialCasesVersions = new Hashtable();
 
     static {
         kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash);
@@ -232,7 +232,7 @@ public class RepositoryId {
         kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash);
     }
 
-    public static final Hashtable kSpecialCasesClasses = new Hashtable();
+    private static final Hashtable kSpecialCasesClasses = new Hashtable();
 
     static {
         kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class);
@@ -244,7 +244,7 @@ public class RepositoryId {
         //kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class);
     }
 
-    public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable();
+    private static final Hashtable kSpecialCasesArrayPrefix = new Hashtable();
 
     static {
         kSpecialCasesArrayPrefix.put(java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
@@ -255,7 +255,7 @@ public class RepositoryId {
         kSpecialCasesArrayPrefix.put(java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix);
     }
 
-    public static final Hashtable kSpecialPrimitives = new Hashtable();
+    private static final Hashtable kSpecialPrimitives = new Hashtable();
 
     static {
         kSpecialPrimitives.put("int","long");
diff --git a/corba/src/share/classes/com/sun/corba/se/spi/logging/CORBALogDomains.java b/corba/src/share/classes/com/sun/corba/se/spi/logging/CORBALogDomains.java
index a2fc7b8f491..978b967c674 100644
--- a/corba/src/share/classes/com/sun/corba/se/spi/logging/CORBALogDomains.java
+++ b/corba/src/share/classes/com/sun/corba/se/spi/logging/CORBALogDomains.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -58,7 +58,7 @@ public abstract class CORBALogDomains {
     private CORBALogDomains() {}
 
     // Top level log domain for CORBA
-    public static String TOP_LEVEL_DOMAIN  = "javax.enterprise.resource.corba";
+    public static final String TOP_LEVEL_DOMAIN  = "javax.enterprise.resource.corba";
 
     public static final String RPC              = "rpc" ;
 
diff --git a/corba/src/share/classes/sun/rmi/rmic/iiop/IDLNames.java b/corba/src/share/classes/sun/rmi/rmic/iiop/IDLNames.java
index 34b3c1f56b5..b69e6d07fa9 100644
--- a/corba/src/share/classes/sun/rmi/rmic/iiop/IDLNames.java
+++ b/corba/src/share/classes/sun/rmi/rmic/iiop/IDLNames.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -71,6 +71,34 @@ public class IDLNames implements sun.rmi.rmic.iiop.Constants {
         (byte)'F',
     };
 
+    // Legal IDL Identifier characters (1 = legal). Note
+    // that '.' (2E) is marked as legal even though it is
+    // not legal in IDL. This allows us to treat a fully
+    // qualified Java name with '.' package separators
+    // uniformly, and is safe because that is the only
+    // legal use of '.' in a Java name.
+
+    private static final byte[] IDL_IDENTIFIER_CHARS = {
+
+        // 0 1 2 3  4 5 6 7  8 9 a b  c d e f
+        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f
+        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 10-1f
+        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,1,0, // 20-2f
+        1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0, // 30-3f
+        0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 40-4f
+        1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, // 50-5f
+        0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 60-6f
+        1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0, // 70-7f
+        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 80-8f
+        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 90-9f
+        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // a0-af
+        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // b0-bf
+        1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // c0-cf
+        0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // d0-df
+        1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // e0-ef
+        0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // f0-ff
+    };
+
     //_____________________________________________________________________
     // Public Interfaces
     //_____________________________________________________________________
@@ -139,7 +167,7 @@ public class IDLNames implements sun.rmi.rmic.iiop.Constants {
         result = replace(result,"x\\U","U");
 
         // Now see if we have any remaining illegal characters (see
-        // RepositoryId.IDL_IDENTIFIER_CHARS array)...
+        // IDL_IDENTIFIER_CHARS array)...
 
         int length = result.length();
         StringBuffer buffer = null;
@@ -148,7 +176,7 @@ public class IDLNames implements sun.rmi.rmic.iiop.Constants {
 
             char c = result.charAt(i);
 
-            if (c > 255 || RepositoryId.IDL_IDENTIFIER_CHARS[c] == 0) {
+            if (c > 255 || IDL_IDENTIFIER_CHARS[c] == 0) {
 
                 // We gotta convert. Have we already started?
 

From dcfcdd72ce123f9c2c902c2114b28d731270682b Mon Sep 17 00:00:00 2001
From: Joe Wang 
Date: Tue, 10 Apr 2012 13:59:21 -0700
Subject: [PATCH 008/463] 7157609: Issues with loop

Reviewed-by: hawtin, lancea, asaha
---
 .../org/apache/xerces/internal/impl/XMLScanner.java | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/jaxp/src/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java b/jaxp/src/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java
index 61fb43d1bc9..0c66aa236fa 100644
--- a/jaxp/src/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java
+++ b/jaxp/src/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java
@@ -402,6 +402,16 @@ public abstract class XMLScanner
 
         boolean dataFoundForTarget = false;
         boolean sawSpace = fEntityScanner.skipSpaces();
+        // since pseudoattributes are *not* attributes,
+        // their quotes don't need to be preserved in external parameter entities.
+        // the XMLEntityScanner#scanLiteral method will continue to
+        // emit -1 in such cases when it finds a quote; this is
+        // fine for other methods that parse scanned entities,
+        // but not for the scanning of pseudoattributes.  So,
+        // temporarily, we must mark the current entity as not being "literal"
+        Entity.ScannedEntity currEnt = fEntityManager.getCurrentEntity();
+        boolean currLiteral = currEnt.literal;
+        currEnt.literal = false;
         while (fEntityScanner.peekChar() != '?') {
             dataFoundForTarget = true;
             String name = scanPseudoAttribute(scanningTextDecl, fString);
@@ -499,6 +509,9 @@ public abstract class XMLScanner
             }
             sawSpace = fEntityScanner.skipSpaces();
         }
+        // restore original literal value
+        if(currLiteral)
+            currEnt.literal = true;
         // REVISIT: should we remove this error reporting?
         if (scanningTextDecl && state != STATE_DONE) {
             reportFatalError("MorePseudoAttributes", null);

From c3a386ef6dac0a4c96472be976be0758238ab134 Mon Sep 17 00:00:00 2001
From: Rob McKenna 
Date: Wed, 11 Apr 2012 17:47:56 -0700
Subject: [PATCH 009/463] 7143606: File.createTempFile should be improved for
 temporary files created by the platform

Reviewed-by: sherman
---
 .../classes/apple/applescript/AppleScriptEngine.java  |  5 +++--
 .../classes/com/sun/java/util/jar/pack/Driver.java    |  7 +++----
 jdk/src/share/classes/java/awt/Font.java              |  7 ++++---
 .../imageio/stream/FileCacheImageInputStream.java     | 10 +++++++---
 .../imageio/stream/FileCacheImageOutputStream.java    | 10 +++++++---
 .../share/classes/javax/management/loading/MLet.java  |  8 +++++---
 jdk/src/share/classes/sun/print/PSPrinterJob.java     |  5 +++--
 jdk/src/share/classes/sun/rmi/server/Activation.java  |  5 +++--
 jdk/src/share/classes/sun/tools/jar/Main.java         |  4 ++--
 .../share/classes/sun/tools/native2ascii/Main.java    | 11 ++++-------
 .../solaris/classes/sun/font/FcFontConfiguration.java |  5 +++--
 jdk/src/solaris/classes/sun/print/UnixPrintJob.java   |  5 +++--
 .../classes/sun/print/UnixPrintServiceLookup.java     |  5 +++--
 13 files changed, 50 insertions(+), 37 deletions(-)

diff --git a/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java b/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java
index 06a20d79e7c..917037b7998 100644
--- a/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java
+++ b/jdk/src/macosx/classes/apple/applescript/AppleScriptEngine.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -26,6 +26,7 @@
 package apple.applescript;
 
 import java.io.*;
+import java.nio.file.Files;
 import java.util.*;
 import java.util.Map.Entry;
 
@@ -297,7 +298,7 @@ public class AppleScriptEngine implements ScriptEngine {
         File tmpfile;
         FileWriter tmpwrite;
         try {
-            tmpfile = File.createTempFile("AppleScriptEngine.", ".scpt");
+            tmpfile = Files.createTempFile("AppleScriptEngine.", ".scpt").toFile();
             tmpwrite = new FileWriter(tmpfile);
 
             // read in our input and write directly to tmpfile
diff --git a/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java b/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java
index f2ab7f0f1d4..960e2d40432 100644
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/Driver.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -35,6 +35,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.text.MessageFormat;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -385,9 +386,7 @@ class Driver {
         if ( base.getParentFile() == null && suffix.equals(".bak"))
             where = new File(".").getAbsoluteFile();
 
-
-        File f = File.createTempFile(prefix, suffix, where);
-        return f;
+        return Files.createTempFile(where.toPath(), prefix, suffix).toFile();
     }
 
     static private
diff --git a/jdk/src/share/classes/java/awt/Font.java b/jdk/src/share/classes/java/awt/Font.java
index e3d48d6a236..4898c8aadc6 100644
--- a/jdk/src/share/classes/java/awt/Font.java
+++ b/jdk/src/share/classes/java/awt/Font.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -36,6 +36,7 @@ import java.awt.geom.Rectangle2D;
 import java.awt.peer.FontPeer;
 import java.io.*;
 import java.lang.ref.SoftReference;
+import java.nio.file.Files;
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
 import java.text.AttributedCharacterIterator.Attribute;
@@ -831,7 +832,7 @@ public class Font implements java.io.Serializable
         File f = null;
         boolean hasPerm = false;
         try {
-            f = File.createTempFile("+~JT", ".tmp", null);
+            f = Files.createTempFile("+~JT", ".tmp").toFile();
             f.delete();
             f = null;
             hasPerm = true;
@@ -881,7 +882,7 @@ public class Font implements java.io.Serializable
             final File tFile = AccessController.doPrivileged(
                 new PrivilegedExceptionAction() {
                     public File run() throws IOException {
-                        return File.createTempFile("+~JF", ".tmp", null);
+                        return Files.createTempFile("+~JF", ".tmp").toFile();
                     }
                 }
             );
diff --git a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java
index dc106cff921..b581de9d0f8 100644
--- a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java
+++ b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -29,6 +29,7 @@ import java.io.File;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.nio.file.Files;
 import com.sun.imageio.stream.StreamCloser;
 import com.sun.imageio.stream.StreamFinalizer;
 import sun.java2d.Disposer;
@@ -97,8 +98,11 @@ public class FileCacheImageInputStream extends ImageInputStreamImpl {
             throw new IllegalArgumentException("Not a directory!");
         }
         this.stream = stream;
-        this.cacheFile =
-            File.createTempFile("imageio", ".tmp", cacheDir);
+        if (cacheDir == null)
+            this.cacheFile = Files.createTempFile("imageio", ".tmp").toFile();
+        else
+            this.cacheFile = Files.createTempFile(cacheDir.toPath(), "imageio", ".tmp")
+                                  .toFile();
         this.cache = new RandomAccessFile(cacheFile, "rw");
 
         this.closeAction = StreamCloser.createCloseAction(this);
diff --git a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java
index 79ce155f23b..c5379b1652a 100644
--- a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java
+++ b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -29,6 +29,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.RandomAccessFile;
+import java.nio.file.Files;
 import com.sun.imageio.stream.StreamCloser;
 
 /**
@@ -83,8 +84,11 @@ public class FileCacheImageOutputStream extends ImageOutputStreamImpl {
             throw new IllegalArgumentException("Not a directory!");
         }
         this.stream = stream;
-        this.cacheFile =
-            File.createTempFile("imageio", ".tmp", cacheDir);
+        if (cacheDir == null)
+            this.cacheFile = Files.createTempFile("imageio", ".tmp").toFile();
+        else
+            this.cacheFile = Files.createTempFile(cacheDir.toPath(), "imageio", ".tmp")
+                                  .toFile();
         this.cache = new RandomAccessFile(cacheFile, "rw");
 
         this.closeAction = StreamCloser.createCloseAction(this);
diff --git a/jdk/src/share/classes/javax/management/loading/MLet.java b/jdk/src/share/classes/javax/management/loading/MLet.java
index 38e7dfad0cf..3d6a5b71aa2 100644
--- a/jdk/src/share/classes/javax/management/loading/MLet.java
+++ b/jdk/src/share/classes/javax/management/loading/MLet.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2008, 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
@@ -44,6 +44,7 @@ import java.lang.reflect.Constructor;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLStreamHandlerFactory;
+import java.nio.file.Files;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -1160,8 +1161,9 @@ public class MLet extends java.net.URLClassLoader
                  try {
                      File directory = new File(libraryDirectory);
                      directory.mkdirs();
-                     File file = File.createTempFile(libname + ".", null,
-                             directory);
+                     File file = Files.createTempFile(directory.toPath(),
+                                                      libname + ".", null)
+                                      .toFile();
                      file.deleteOnExit();
                      FileOutputStream fileOutput = new FileOutputStream(file);
                      try {
diff --git a/jdk/src/share/classes/sun/print/PSPrinterJob.java b/jdk/src/share/classes/sun/print/PSPrinterJob.java
index 49584f2f8a2..bae8a3e0acf 100644
--- a/jdk/src/share/classes/sun/print/PSPrinterJob.java
+++ b/jdk/src/share/classes/sun/print/PSPrinterJob.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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
@@ -97,6 +97,7 @@ import sun.font.FontUtilities;
 import java.nio.charset.*;
 import java.nio.CharBuffer;
 import java.nio.ByteBuffer;
+import java.nio.file.Files;
 
 //REMIND: Remove use of this class when IPPPrintService is moved to share directory.
 import java.lang.reflect.Method;
@@ -659,7 +660,7 @@ public class PSPrinterJob extends RasterPrinterJob {
                      * is not removed for some reason, request that it is
                      * removed when the VM exits.
                      */
-                    spoolFile = File.createTempFile("javaprint", ".ps", null);
+                    spoolFile = Files.createTempFile("javaprint", ".ps").toFile();
                     spoolFile.deleteOnExit();
 
                 result = new FileOutputStream(spoolFile);
diff --git a/jdk/src/share/classes/sun/rmi/server/Activation.java b/jdk/src/share/classes/sun/rmi/server/Activation.java
index c1ec95e6784..d1946fafc2f 100644
--- a/jdk/src/share/classes/sun/rmi/server/Activation.java
+++ b/jdk/src/share/classes/sun/rmi/server/Activation.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2006, 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
@@ -43,6 +43,7 @@ import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.SocketAddress;
 import java.net.SocketException;
+import java.nio.file.Files;
 import java.nio.channels.Channel;
 import java.nio.channels.ServerSocketChannel;
 import java.rmi.AccessException;
@@ -1940,7 +1941,7 @@ public class Activation implements Serializable {
                     new PrivilegedExceptionAction() {
                         public Void run() throws IOException {
                             File file =
-                                File.createTempFile("rmid-err", null, null);
+                                Files.createTempFile("rmid-err", null).toFile();
                             PrintStream errStream =
                                 new PrintStream(new FileOutputStream(file));
                             System.setErr(errStream);
diff --git a/jdk/src/share/classes/sun/tools/jar/Main.java b/jdk/src/share/classes/sun/tools/jar/Main.java
index 486b19319ab..22ef9f7aee6 100644
--- a/jdk/src/share/classes/sun/tools/jar/Main.java
+++ b/jdk/src/share/classes/sun/tools/jar/Main.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -137,7 +137,7 @@ class Main {
         File dir = file.getParentFile();
         if (dir == null)
             dir = new File(".");
-        return File.createTempFile("jartmp", null, dir);
+        return Files.createTempFile(dir.toPath(), "jartmp", null).toFile();
     }
 
     private boolean ok;
diff --git a/jdk/src/share/classes/sun/tools/native2ascii/Main.java b/jdk/src/share/classes/sun/tools/native2ascii/Main.java
index 0423699bba4..6a941fe2e88 100644
--- a/jdk/src/share/classes/sun/tools/native2ascii/Main.java
+++ b/jdk/src/share/classes/sun/tools/native2ascii/Main.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -71,6 +71,7 @@ import java.text.MessageFormat;
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.Charset;
 import java.nio.charset.IllegalCharsetNameException;
+import java.nio.file.Files;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.UnsupportedCharsetException;
 import sun.tools.native2ascii.A2NFilter;
@@ -240,9 +241,7 @@ public class Main {
             if (tempDir == null)
                 tempDir = new File(System.getProperty("user.dir"));
 
-            tempFile = File.createTempFile("_N2A",
-                                           ".TMP",
-                                            tempDir);
+            tempFile = Files.createTempFile(tempDir.toPath(), "_N2A", ".TMP").toFile();
             tempFile.deleteOnExit();
 
             try {
@@ -292,9 +291,7 @@ public class Main {
             File tempDir = f.getParentFile();
             if (tempDir == null)
                 tempDir = new File(System.getProperty("user.dir"));
-            tempFile =  File.createTempFile("_N2A",
-                                            ".TMP",
-                                            tempDir);
+            tempFile =  Files.createTempFile(tempDir.toPath(), "_N2A", ".TMP").toFile();
             tempFile.deleteOnExit();
 
             try {
diff --git a/jdk/src/solaris/classes/sun/font/FcFontConfiguration.java b/jdk/src/solaris/classes/sun/font/FcFontConfiguration.java
index 14d8e7ed221..e33e08a867b 100644
--- a/jdk/src/solaris/classes/sun/font/FcFontConfiguration.java
+++ b/jdk/src/solaris/classes/sun/font/FcFontConfiguration.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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
@@ -33,6 +33,7 @@ import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.charset.Charset;
+import java.nio.file.Files;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Properties;
@@ -387,7 +388,7 @@ public class FcFontConfiguration extends FontConfiguration {
             File fcInfoFile = getFcInfoFile();
             File dir = fcInfoFile.getParentFile();
             dir.mkdirs();
-            File tempFile = File.createTempFile("fcinfo", null, dir);
+            File tempFile = Files.createTempFile(dir.toPath(), "fcinfo", null).toFile();
             FileOutputStream fos = new FileOutputStream(tempFile);
             props.store(fos,
                       "JDK Font Configuration Generated File: *Do Not Edit*");
diff --git a/jdk/src/solaris/classes/sun/print/UnixPrintJob.java b/jdk/src/solaris/classes/sun/print/UnixPrintJob.java
index 206650de40e..620cf1cdd44 100644
--- a/jdk/src/solaris/classes/sun/print/UnixPrintJob.java
+++ b/jdk/src/solaris/classes/sun/print/UnixPrintJob.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -42,6 +42,7 @@ import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
+import java.nio.file.Files;
 import java.util.Vector;
 
 import javax.print.CancelablePrintJob;
@@ -938,7 +939,7 @@ public class UnixPrintJob implements CancelablePrintJob {
                      * is not removed for some reason, request that it is
                      * removed when the VM exits.
                      */
-                    spoolFile = File.createTempFile("javaprint", ".ps", null);
+                    spoolFile = Files.createTempFile("javaprint", ".ps").toFile();
                     spoolFile.deleteOnExit();
                 }
                 result = new FileOutputStream(spoolFile);
diff --git a/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java b/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
index c1de9bc1849..ba21006e0db 100644
--- a/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
+++ b/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -51,6 +51,7 @@ import javax.print.attribute.standard.PrinterName;
 import java.io.File;
 import java.io.FileReader;
 import java.net.URL;
+import java.nio.file.Files;
 
 /*
  * Remind: This class uses solaris commands. We also need a linux
@@ -714,7 +715,7 @@ public class UnixPrintServiceLookup extends PrintServiceLookup
 
                         Process proc;
                         BufferedReader bufferedReader = null;
-                        File f = File.createTempFile("prn","xc");
+                        File f = Files.createTempFile("prn","xc").toFile();
                         cmd[2] = cmd[2]+">"+f.getAbsolutePath();
 
                         proc = Runtime.getRuntime().exec(cmd);

From 05ffd97b08d99ab516321cfc20e7e69e667e5e7d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Forax?= 
Date: Wed, 2 May 2012 20:01:59 +0100
Subject: [PATCH 010/463] 7165102: Only run assertion on Integer autoboxing
 cache size once

Reviewed-by: darcy, alanb
---
 jdk/src/share/classes/java/lang/Integer.java | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/jdk/src/share/classes/java/lang/Integer.java b/jdk/src/share/classes/java/lang/Integer.java
index 88acdfa11da..c33e90a5e49 100644
--- a/jdk/src/share/classes/java/lang/Integer.java
+++ b/jdk/src/share/classes/java/lang/Integer.java
@@ -780,6 +780,9 @@ public final class Integer extends Number implements Comparable {
             int j = low;
             for(int k = 0; k < cache.length; k++)
                 cache[k] = new Integer(j++);
+
+            // range [-128, 127] must be interned (JLS7 5.1.7)
+            assert IntegerCache.high >= 127;
         }
 
         private IntegerCache() {}
@@ -801,7 +804,6 @@ public final class Integer extends Number implements Comparable {
      * @since  1.5
      */
     public static Integer valueOf(int i) {
-        assert IntegerCache.high >= 127;
         if (i >= IntegerCache.low && i <= IntegerCache.high)
             return IntegerCache.cache[i + (-IntegerCache.low)];
         return new Integer(i);

From b4c2c567d6c0a6e6cd02a03ea6c16cd7f148dc21 Mon Sep 17 00:00:00 2001
From: Jim Gish 
Date: Wed, 2 May 2012 21:46:31 +0100
Subject: [PATCH 011/463] 7160714: Strange or obsolete @see tags in some
 exception java.util javadoc

Reviewed-by: mduigou, dholmes, alanb
---
 .../share/classes/java/util/NoSuchElementException.java  | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/jdk/src/share/classes/java/util/NoSuchElementException.java b/jdk/src/share/classes/java/util/NoSuchElementException.java
index 88ff2c079a4..15e1aad98c2 100644
--- a/jdk/src/share/classes/java/util/NoSuchElementException.java
+++ b/jdk/src/share/classes/java/util/NoSuchElementException.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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
@@ -26,13 +26,12 @@
 package java.util;
 
 /**
- * Thrown by the nextElement method of an
- * Enumeration to indicate that there are no more
- * elements in the enumeration.
+ * Thrown by various accessor methods to indicate that the element being requested
+ * does not exist.
  *
  * @author  unascribed
- * @see     java.util.Enumeration
  * @see     java.util.Enumeration#nextElement()
+ * @see     java.util.Iterator#next()
  * @since   JDK1.0
  */
 public

From 0705c620501d77c799d85433fdfd46719fa96f63 Mon Sep 17 00:00:00 2001
From: Sergey Bylokhov 
Date: Thu, 3 May 2012 18:29:00 +0400
Subject: [PATCH 012/463] 7160623: [macosx] Editable TextArea/TextField are
 blocking GUI applications from exit

Reviewed-by: anthony, art
---
 .../macosx/classes/sun/lwawt/LWComponentPeer.java    |  2 +-
 .../classes/sun/lwawt/LWTextComponentPeer.java       | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
index a7b15e07c96..0b8b290f082 100644
--- a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
@@ -372,7 +372,7 @@ public abstract class LWComponentPeer
     }
 
     @Override
-    public void dispose() {
+    public final void dispose() {
         if (disposed.compareAndSet(false, true)) {
             disposeImpl();
         }
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java
index 5884b119261..01de62b6c96 100644
--- a/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java
@@ -81,6 +81,18 @@ abstract class LWTextComponentPeer
Date: Thu, 3 May 2012 19:22:38 +0400
Subject: [PATCH 013/463] 7124376: [macosx] Modal dialog lost focus

Reviewed-by: anthony
---
 .../classes/sun/lwawt/LWWindowPeer.java       |  2 +
 .../classes/sun/lwawt/PlatformWindow.java     |  2 +
 .../lwawt/macosx/CPlatformEmbeddedFrame.java  |  3 +
 .../sun/lwawt/macosx/CPlatformWindow.java     | 10 +++
 jdk/src/macosx/native/sun/awt/AWTView.m       | 19 ++--
 jdk/src/macosx/native/sun/awt/AWTWindow.h     |  2 +
 jdk/src/macosx/native/sun/awt/AWTWindow.m     | 86 +++++++++++++------
 7 files changed, 94 insertions(+), 30 deletions(-)

diff --git a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
index 9e3796c7083..82d97c01aaa 100644
--- a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
@@ -409,6 +409,8 @@ public class LWWindowPeer
         synchronized (getPeerTreeLock()) {
             this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null;
         }
+
+        platformWindow.setModalBlocked(blocked);
     }
 
     @Override
diff --git a/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java b/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java
index 0d2a8083752..378dcab0329 100644
--- a/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java
+++ b/jdk/src/macosx/classes/sun/lwawt/PlatformWindow.java
@@ -108,6 +108,8 @@ public interface PlatformWindow {
     public void flip(int x1, int y1, int x2, int y2,
                      BufferCapabilities.FlipContents flipAction);
 
+    public void setModalBlocked(boolean blocked);
+
     public void toFront();
 
     public void toBack();
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java
index c355445ac83..cf9c455aba8 100644
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java
@@ -205,4 +205,7 @@ public class CPlatformEmbeddedFrame implements PlatformWindow {
 
     @Override
     public void setWindowState(int windowState) {}
+
+    @Override
+    public void setModalBlocked(boolean blocked) {}
 }
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
index 9f8c8f545d0..bfaab65d196 100644
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
@@ -61,6 +61,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
     private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
     private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
     private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY);
+    private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
     private static native void nativeSynthesizeMouseEnteredExitedEvents(long nsWindowPtr);
 
     private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr);
@@ -800,6 +801,15 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
         //       value when the native notification comes to us
     }
 
+    @Override
+    public void setModalBlocked(boolean blocked) {
+        if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
+            return;
+        }
+
+        nativeSetEnabled(getNSWindowPtr(), !blocked);
+    }
+
     // ----------------------------------------------------------------------
     //                          UTILITY METHODS
     // ----------------------------------------------------------------------
diff --git a/jdk/src/macosx/native/sun/awt/AWTView.m b/jdk/src/macosx/native/sun/awt/AWTView.m
index 896d05c4c72..4f3bae7933a 100644
--- a/jdk/src/macosx/native/sun/awt/AWTView.m
+++ b/jdk/src/macosx/native/sun/awt/AWTView.m
@@ -81,7 +81,7 @@ AWT_ASSERT_APPKIT_THREAD;
     fEnablePressAndHold = shouldUsePressAndHold();
     fInPressAndHold = NO;
     fPAHNeedsToSelect = NO;
-    
+
     mouseIsOver = NO;
 
     if (windowLayer != nil) {
@@ -302,16 +302,25 @@ AWT_ASSERT_APPKIT_THREAD;
  */
 
 -(void) deliverJavaMouseEvent: (NSEvent *) event {
-    
-    NSEventType type = [event type];    
-    
+    BOOL isEnabled = YES;
+    NSWindow* window = [self window];
+    if ([window isKindOfClass: [AWTWindow class]]) {
+        isEnabled = [(AWTWindow*)window isEnabled];
+    }
+
+    if (!isEnabled) {
+        return;
+    }
+
+    NSEventType type = [event type];
+
     // check synthesized mouse entered/exited events
     if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {
         return;
     }else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {
         mouseIsOver = !mouseIsOver;
     }
-    
+
     [AWTToolkit eventCountPlusPlus];
 
     JNIEnv *env = [ThreadUtilities getJNIEnv];
diff --git a/jdk/src/macosx/native/sun/awt/AWTWindow.h b/jdk/src/macosx/native/sun/awt/AWTWindow.h
index 58280927fbf..39863eef09e 100644
--- a/jdk/src/macosx/native/sun/awt/AWTWindow.h
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.h
@@ -42,6 +42,7 @@
     NSSize javaMinSize;
     NSSize javaMaxSize;
     jint styleBits;
+    BOOL isEnabled;
 }
 
 @property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
@@ -49,6 +50,7 @@
 @property (nonatomic) NSSize javaMinSize;
 @property (nonatomic) NSSize javaMaxSize;
 @property (nonatomic) jint styleBits;
+@property (nonatomic) BOOL isEnabled;
 
 - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
                     styleBits:(jint)styleBits
diff --git a/jdk/src/macosx/native/sun/awt/AWTWindow.m b/jdk/src/macosx/native/sun/awt/AWTWindow.m
index 7add839f8e6..3fcf9f0cd65 100644
--- a/jdk/src/macosx/native/sun/awt/AWTWindow.m
+++ b/jdk/src/macosx/native/sun/awt/AWTWindow.m
@@ -58,6 +58,7 @@ static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
 @synthesize javaMinSize;
 @synthesize javaMaxSize;
 @synthesize styleBits;
+@synthesize isEnabled;
 
 - (void) updateMinMaxSize:(BOOL)resizable {
     if (resizable) {
@@ -157,6 +158,7 @@ AWT_ASSERT_APPKIT_THREAD;
 
     if (self == nil) return nil; // no hope
 
+    self.isEnabled = YES;
     self.javaPlatformWindow = platformWindow;
     self.styleBits = bits;
     [self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
@@ -170,22 +172,22 @@ AWT_ASSERT_APPKIT_THREAD;
     return self;
 }
 
-// checks that this window is under the mouse cursor and this point is not overlapped by others windows 
+// checks that this window is under the mouse cursor and this point is not overlapped by others windows
 - (BOOL) isTopmostWindowUnderMouse {
-    
-    int currentWinID = [self windowNumber]; 
-    
-    NSRect screenRect = [[NSScreen mainScreen] frame];    
+
+    int currentWinID = [self windowNumber];
+
+    NSRect screenRect = [[NSScreen mainScreen] frame];
     NSPoint nsMouseLocation = [NSEvent mouseLocation];
-    CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);    
-    
+    CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
+
     NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
-    
-    
+
+
     for (NSDictionary *window in windows) {
         int layer = [[window objectForKey:(id)kCGWindowLayer] intValue];
         if (layer == 0) {
-            int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];            
+            int winID = [[window objectForKey:(id)kCGWindowNumber] intValue];
             CGRect rect;
             CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
             if (CGRectContainsPoint(rect, cgMouseLocation)) {
@@ -199,23 +201,23 @@ AWT_ASSERT_APPKIT_THREAD;
 }
 
 - (void) synthesizeMouseEnteredExitedEvents {
-    
+
     int eventType = 0;
     BOOL isUnderMouse = [self isTopmostWindowUnderMouse];
     BOOL mouseIsOver = [[self contentView] mouseIsOver];
-    
+
     if (isUnderMouse && !mouseIsOver) {
         eventType = NSMouseEntered;
     } else if (!isUnderMouse && mouseIsOver) {
-        eventType = NSMouseExited;        
+        eventType = NSMouseExited;
     } else {
         return;
     }
-    
-    NSPoint screenLocation = [NSEvent mouseLocation];        
-    NSPoint windowLocation = [self convertScreenToBase: screenLocation];        
+
+    NSPoint screenLocation = [NSEvent mouseLocation];
+    NSPoint windowLocation = [self convertScreenToBase: screenLocation];
     int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
-    
+
     NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
                                                   location: windowLocation
                                              modifierFlags: modifierFlags
@@ -226,7 +228,7 @@ AWT_ASSERT_APPKIT_THREAD;
                                             trackingNumber: 0
                                                   userData: nil
                             ];
-    
+
     [[self contentView] deliverJavaMouseEvent: mouseEvent];
 }
 
@@ -239,16 +241,15 @@ AWT_ASSERT_APPKIT_THREAD;
     [super dealloc];
 }
 
-
 // NSWindow overrides
 - (BOOL) canBecomeKeyWindow {
 AWT_ASSERT_APPKIT_THREAD;
-    return IS(self.styleBits, SHOULD_BECOME_KEY);
+    return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_KEY);
 }
 
 - (BOOL) canBecomeMainWindow {
 AWT_ASSERT_APPKIT_THREAD;
-    return IS(self.styleBits, SHOULD_BECOME_MAIN);
+    return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN);
 }
 
 - (BOOL) worksWhenModal {
@@ -562,6 +563,27 @@ AWT_ASSERT_APPKIT_THREAD;
     size->height = MAX(size->height, minHeight);
 }
 
+- (void) setEnabled: (BOOL)flag {
+    self.isEnabled = flag;
+
+    if (IS(self.styleBits, CLOSEABLE)) {
+        [[self standardWindowButton:NSWindowCloseButton] setEnabled: flag];
+    }
+
+    if (IS(self.styleBits, MINIMIZABLE)) {
+        [[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag];
+    }
+
+    if (IS(self.styleBits, ZOOMABLE)) {
+        [[self standardWindowButton:NSWindowZoomButton] setEnabled: flag];
+    }
+
+    if (IS(self.styleBits, RESIZABLE)) {
+        [self updateMinMaxSize:flag];
+        [self setShowsResizeIndicator:flag];
+    }
+}
+
 @end // AWTWindow
 
 
@@ -729,7 +751,7 @@ AWT_ASSERT_NOT_APPKIT_THREAD;
         // ensure we repaint the whole window after the resize operation
         // (this will also re-enable screen updates, which were disabled above)
         // TODO: send PaintEvent
-        
+
         [window synthesizeMouseEnteredExitedEvents];
     }];
 
@@ -969,14 +991,14 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMou
 {
     JNF_COCOA_ENTER(env);
     AWT_ASSERT_NOT_APPKIT_THREAD;
-    
+
     AWTWindow *window = OBJC(windowPtr);
     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
         AWT_ASSERT_APPKIT_THREAD;
-        
+
         [window synthesizeMouseEnteredExitedEvents];
     }];
-    
+
     JNF_COCOA_EXIT(env);
 }
 
@@ -1056,3 +1078,17 @@ JNF_COCOA_EXIT(env);
 
     return underMouse;
 }
+
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled
+(JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled)
+{
+JNF_COCOA_ENTER(env);
+
+    AWTWindow *window = OBJC(windowPtr);
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        [window setEnabled: isEnabled];
+    }];
+
+JNF_COCOA_EXIT(env);
+}
+

From e3ab8ba856ce51b61f34e8cd8d892061a8d2f2c3 Mon Sep 17 00:00:00 2001
From: Alexander Zuev 
Date: Thu, 3 May 2012 21:54:29 +0400
Subject: [PATCH 014/463] 7148289: [macosx] Deadlock in
 sun.lwawt.macosx.CWrapper$NSScreen.visibleFrame

Reviewed-by: leonidr
---
 .../macosx/CToolkitThreadBlockedHandler.java  |  7 ++--
 .../classes/sun/lwawt/macosx/LWCToolkit.java  |  4 +++
 jdk/src/macosx/native/sun/awt/LWCToolkit.m    | 34 +++++++++++++++++++
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java b/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
index 2d36a914122..95d15a8feaa 100644
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CToolkitThreadBlockedHandler.java
@@ -27,9 +27,9 @@ package sun.lwawt.macosx;
 
 import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
 
-// TODO:BG this class is really a NOOP right now, but should be filled in if needed.
-
 final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler {
+    private final LWCToolkit toolkit = (LWCToolkit)java.awt.Toolkit.getDefaultToolkit();
+
     public void lock() {
     }
 
@@ -41,9 +41,10 @@ final class CToolkitThreadBlockedHandler implements ToolkitThreadBlockedHandler
     }
 
     public void enter() {
+        toolkit.startNativeNestedEventLoop();
     }
 
     public void exit() {
+        toolkit.stopNativeNestedEventLoop();
     }
-
 }
diff --git a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
index 05c4ceeaec8..fa13d0ef675 100644
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
@@ -63,6 +63,10 @@ public class LWCToolkit extends LWToolkit {
 
     private static native void initIDs();
 
+    static native void startNativeNestedEventLoop();
+
+    static native void stopNativeNestedEventLoop();
+
     private static CInputMethodDescriptor sInputMethodDescriptor;
 
     static {
diff --git a/jdk/src/macosx/native/sun/awt/LWCToolkit.m b/jdk/src/macosx/native/sun/awt/LWCToolkit.m
index 8a95cd38d3d..173154a151c 100644
--- a/jdk/src/macosx/native/sun/awt/LWCToolkit.m
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m
@@ -42,6 +42,7 @@ jint* gButtonDownMasks;
 @implementation AWTToolkit
 
 static long eventCount;
+static bool shouldKeepRunningNestedLoop = NO;
 
 + (long) getEventCount{
     return eventCount;
@@ -456,3 +457,36 @@ Java_sun_font_FontManager_populateFontFileNameMap
 {
 
 }
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    startNativeNestedEventLoop
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_startNativeNestedEventLoop
+(JNIEnv *env, jclass cls)
+{
+    if(!shouldKeepRunningNestedLoop) {
+        NSRunLoop *theRL = [NSRunLoop currentRunLoop];
+        NSApplication * app = [NSApplication sharedApplication];
+        shouldKeepRunningNestedLoop = YES;
+        while (shouldKeepRunningNestedLoop && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
+        {
+            NSEvent * event = [app nextEventMatchingMask: 0xFFFFFFFF untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES];
+            if (event != nil) {
+                [app sendEvent: event];
+            }
+        }
+    }
+}
+
+/*
+ * Class:     sun_lwawt_macosx_LWCToolkit
+ * Method:    stopNativeNestedEventLoop
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopNativeNestedEventLoop
+(JNIEnv *env, jclass cls)
+{
+    shouldKeepRunningNestedLoop = NO;
+}

From 045ba7db6b247b4e9e639709851a3ca121c294a9 Mon Sep 17 00:00:00 2001
From: Alexander Scherbatiy 
Date: Fri, 4 May 2012 13:15:49 +0400
Subject: [PATCH 015/463] 7024963: Notepad demo: remove non-translatable
 resources from Notepad.properties file

Reviewed-by: rupashka
---
 jdk/src/share/demo/jfc/Notepad/Notepad.java   | 250 ++++++------------
 .../jfc/Notepad/resources/Notepad.properties  |  30 ---
 .../jfc/Notepad/resources/system.properties   |  12 +
 3 files changed, 92 insertions(+), 200 deletions(-)
 create mode 100644 jdk/src/share/demo/jfc/Notepad/resources/system.properties

diff --git a/jdk/src/share/demo/jfc/Notepad/Notepad.java b/jdk/src/share/demo/jfc/Notepad/Notepad.java
index c80966920fb..d023dee7990 100644
--- a/jdk/src/share/demo/jfc/Notepad/Notepad.java
+++ b/jdk/src/share/demo/jfc/Notepad/Notepad.java
@@ -39,71 +39,18 @@
 
 
 
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.FileDialog;
-import java.awt.Font;
-import java.awt.Frame;
-import java.awt.Graphics;
-import java.awt.Insets;
-import java.awt.event.ActionEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.StringTokenizer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.BorderFactory;
-import javax.swing.Box;
-import javax.swing.BoxLayout;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JProgressBar;
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.JToolBar;
-import javax.swing.JViewport;
-import javax.swing.SwingUtilities;
-import javax.swing.UIManager;
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.logging.*;
+import javax.swing.*;
+import javax.swing.undo.*;
+import javax.swing.text.*;
+import javax.swing.event.*;
 import javax.swing.UIManager.LookAndFeelInfo;
-import javax.swing.event.UndoableEditEvent;
-import javax.swing.event.UndoableEditListener;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Document;
-import javax.swing.text.JTextComponent;
-import javax.swing.text.PlainDocument;
-import javax.swing.text.Segment;
-import javax.swing.text.TextAction;
-import javax.swing.undo.CannotRedoException;
-import javax.swing.undo.CannotUndoException;
-import javax.swing.undo.UndoManager;
 
 
 /**
@@ -115,16 +62,27 @@ import javax.swing.undo.UndoManager;
 @SuppressWarnings("serial")
 class Notepad extends JPanel {
 
+    private static Properties properties;
     private static ResourceBundle resources;
     private final static String EXIT_AFTER_PAINT = "-exit";
     private static boolean exitAfterFirstPaint;
 
+    private static final String[] MENUBAR_KEYS = {"file", "edit", "debug"};
+    private static final String[] TOOLBAR_KEYS = {"new", "open", "save", "-", "cut", "copy", "paste"};
+    private static final String[] FILE_KEYS = {"new", "open", "save", "-", "exit"};
+    private static final String[] EDIT_KEYS = {"cut", "copy", "paste", "-", "undo", "redo"};
+    private static final String[] DEBUG_KEYS = {"dump", "showElementTree"};
+
     static {
         try {
+            properties = new Properties();
+            properties.load(Notepad.class.getResourceAsStream(
+                    "resources/system.properties"));
             resources = ResourceBundle.getBundle("resources.Notepad",
                     Locale.getDefault());
-        } catch (MissingResourceException mre) {
-            System.err.println("resources/Notepad.properties not found");
+        } catch (MissingResourceException | IOException  e) {
+            System.err.println("resources/Notepad.properties "
+                    + "or resources/system.properties not found");
             System.exit(1);
         }
     }
@@ -163,26 +121,22 @@ class Notepad extends JPanel {
         // install the command table
         commands = new HashMap();
         Action[] actions = getActions();
-        for (int i = 0; i < actions.length; i++) {
-            Action a = actions[i];
-            //commands.put(a.getText(Action.NAME), a);
+        for (Action a : actions) {
             commands.put(a.getValue(Action.NAME), a);
         }
 
         JScrollPane scroller = new JScrollPane();
         JViewport port = scroller.getViewport();
         port.add(editor);
-        try {
-            String vpFlag = resources.getString("ViewportBackingStore");
+
+        String vpFlag = getProperty("ViewportBackingStore");
+        if (vpFlag != null) {
             Boolean bs = Boolean.valueOf(vpFlag);
-            port.setScrollMode(bs.booleanValue()
+            port.setScrollMode(bs
                     ? JViewport.BACKINGSTORE_SCROLL_MODE
                     : JViewport.BLIT_SCROLL_MODE);
-        } catch (MissingResourceException ignored) {
-            // just use the viewport default
         }
 
-        menuItems = new HashMap();
         JPanel panel = new JPanel();
         panel.setLayout(new BorderLayout());
         panel.add("North", createToolbar());
@@ -191,31 +145,26 @@ class Notepad extends JPanel {
         add("South", createStatusbar());
     }
 
-    public static void main(String[] args) {
-        try {
-            if (args.length > 0 && args[0].equals(EXIT_AFTER_PAINT)) {
-                exitAfterFirstPaint = true;
-            }
-            SwingUtilities.invokeAndWait(new Runnable() {
-
-                public void run() {
-                    JFrame frame = new JFrame();
-                    frame.setTitle(resources.getString("Title"));
-                    frame.setBackground(Color.lightGray);
-                    frame.getContentPane().setLayout(new BorderLayout());
-                    Notepad notepad = new Notepad();
-                    frame.getContentPane().add("Center", notepad);
-                    frame.setJMenuBar(notepad.createMenubar());
-                    frame.addWindowListener(new AppCloser());
-                    frame.pack();
-                    frame.setSize(500, 600);
-                    frame.setVisible(true);
-                }
-            });
-        } catch (Throwable t) {
-            Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE,
-                    "uncaught exception", t);
+    public static void main(String[] args) throws Exception {
+        if (args.length > 0 && args[0].equals(EXIT_AFTER_PAINT)) {
+            exitAfterFirstPaint = true;
         }
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            public void run() {
+                JFrame frame = new JFrame();
+                frame.setTitle(resources.getString("Title"));
+                frame.setBackground(Color.lightGray);
+                frame.getContentPane().setLayout(new BorderLayout());
+                Notepad notepad = new Notepad();
+                frame.getContentPane().add("Center", notepad);
+                frame.setJMenuBar(notepad.createMenubar());
+                frame.addWindowListener(new AppCloser());
+                frame.pack();
+                frame.setSize(500, 600);
+                frame.setVisible(true);
+            }
+        });
     }
 
     /**
@@ -274,9 +223,7 @@ class Notepad extends JPanel {
 
     /**
      * This is the hook through which all menu items are
-     * created.  It registers the result with the menuitem
-     * hashtable so that it can be fetched with getMenuItem().
-     * @see #getMenuItem
+     * created.
      */
     protected JMenuItem createMenuItem(String cmd) {
         JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
@@ -285,7 +232,7 @@ class Notepad extends JPanel {
             mi.setHorizontalTextPosition(JButton.RIGHT);
             mi.setIcon(new ImageIcon(url));
         }
-        String astr = getResourceString(cmd + actionSuffix);
+        String astr = getProperty(cmd + actionSuffix);
         if (astr == null) {
             astr = cmd;
         }
@@ -298,25 +245,17 @@ class Notepad extends JPanel {
         } else {
             mi.setEnabled(false);
         }
-        menuItems.put(cmd, mi);
         return mi;
     }
 
-    /**
-     * Fetch the menu item that was created for the given
-     * command.
-     * @param cmd  Name of the action.
-     * @returns item created for the given command or null
-     *  if one wasn't created.
-     */
-    protected JMenuItem getMenuItem(String cmd) {
-        return menuItems.get(cmd);
-    }
-
     protected Action getAction(String cmd) {
         return commands.get(cmd);
     }
 
+    protected String getProperty(String key) {
+        return properties.getProperty(key);
+    }
+
     protected String getResourceString(String nm) {
         String str;
         try {
@@ -330,20 +269,11 @@ class Notepad extends JPanel {
     protected URL getResource(String key) {
         String name = getResourceString(key);
         if (name != null) {
-            URL url = this.getClass().getResource(name);
-            return url;
+            return this.getClass().getResource(name);
         }
         return null;
     }
 
-    protected Container getToolbar() {
-        return toolbar;
-    }
-
-    protected JMenuBar getMenubar() {
-        return menubar;
-    }
-
     /**
      * Create a status bar
      */
@@ -368,12 +298,11 @@ class Notepad extends JPanel {
      */
     private Component createToolbar() {
         toolbar = new JToolBar();
-        String[] toolKeys = tokenize(getResourceString("toolbar"));
-        for (int i = 0; i < toolKeys.length; i++) {
-            if (toolKeys[i].equals("-")) {
+        for (String toolKey: TOOLBAR_KEYS) {
+            if (toolKey.equals("-")) {
                 toolbar.add(Box.createHorizontalStrut(5));
             } else {
-                toolbar.add(createTool(toolKeys[i]));
+                toolbar.add(createTool(toolKey));
             }
         }
         toolbar.add(Box.createHorizontalGlue());
@@ -408,7 +337,7 @@ class Notepad extends JPanel {
         b.setRequestFocusEnabled(false);
         b.setMargin(new Insets(1, 1, 1, 1));
 
-        String astr = getResourceString(key + actionSuffix);
+        String astr = getProperty(key + actionSuffix);
         if (astr == null) {
             astr = key;
         }
@@ -428,44 +357,18 @@ class Notepad extends JPanel {
         return b;
     }
 
-    /**
-     * Take the given string and chop it up into a series
-     * of strings on whitespace boundaries.  This is useful
-     * for trying to get an array of strings out of the
-     * resource file.
-     */
-    protected String[] tokenize(String input) {
-        List v = new ArrayList();
-        StringTokenizer t = new StringTokenizer(input);
-        String cmd[];
-
-        while (t.hasMoreTokens()) {
-            v.add(t.nextToken());
-        }
-        cmd = new String[v.size()];
-        for (int i = 0; i < cmd.length; i++) {
-            cmd[i] = v.get(i);
-        }
-
-        return cmd;
-    }
-
     /**
      * Create the menubar for the app.  By default this pulls the
      * definition of the menu from the associated resource file.
      */
     protected JMenuBar createMenubar() {
-        JMenuItem mi;
         JMenuBar mb = new JMenuBar();
-
-        String[] menuKeys = tokenize(getResourceString("menubar"));
-        for (int i = 0; i < menuKeys.length; i++) {
-            JMenu m = createMenu(menuKeys[i]);
+        for(String menuKey: MENUBAR_KEYS){
+            JMenu m = createMenu(menuKey);
             if (m != null) {
                 mb.add(m);
             }
         }
-        this.menubar = mb;
         return mb;
     }
 
@@ -474,19 +377,32 @@ class Notepad extends JPanel {
      * definition of the menu from the associated resource file.
      */
     protected JMenu createMenu(String key) {
-        String[] itemKeys = tokenize(getResourceString(key));
-        JMenu menu = new JMenu(getResourceString(key + "Label"));
-        for (int i = 0; i < itemKeys.length; i++) {
-            if (itemKeys[i].equals("-")) {
+        JMenu menu = new JMenu(getResourceString(key + labelSuffix));
+        for (String itemKey: getItemKeys(key)) {
+            if (itemKey.equals("-")) {
                 menu.addSeparator();
             } else {
-                JMenuItem mi = createMenuItem(itemKeys[i]);
+                JMenuItem mi = createMenuItem(itemKey);
                 menu.add(mi);
             }
         }
         return menu;
     }
 
+    // get keys for menus
+    private String[] getItemKeys(String key) {
+        switch (key) {
+            case "file":
+                return FILE_KEYS;
+            case "edit":
+                return EDIT_KEYS;
+            case "debug":
+                return DEBUG_KEYS;
+            default:
+                return null;
+        }
+    }
+
     // Yarked from JMenu, ideally this would be public.
     protected PropertyChangeListener createActionChangeListener(JMenuItem b) {
         return new ActionChangedListener(b);
@@ -516,13 +432,11 @@ class Notepad extends JPanel {
     }
     private JTextComponent editor;
     private Map commands;
-    private Map menuItems;
-    private JMenuBar menubar;
     private JToolBar toolbar;
     private JComponent status;
     private JFrame elementTreeFrame;
     protected ElementTreePanel elementTreePanel;
-    protected FileDialog fileDialog;
+
     /**
      * Listener for the edits on the current document.
      */
@@ -773,10 +687,6 @@ class Notepad extends JPanel {
             super(showElementTreeAction);
         }
 
-        ShowElementTreeAction(String nm) {
-            super(nm);
-        }
-
         public void actionPerformed(ActionEvent e) {
             if (elementTreeFrame == null) {
                 // Create a frame containing an instance of
diff --git a/jdk/src/share/demo/jfc/Notepad/resources/Notepad.properties b/jdk/src/share/demo/jfc/Notepad/resources/Notepad.properties
index ef61d6fd3c4..d43e350942c 100644
--- a/jdk/src/share/demo/jfc/Notepad/resources/Notepad.properties
+++ b/jdk/src/share/demo/jfc/Notepad/resources/Notepad.properties
@@ -3,16 +3,6 @@
 
 Title=Notepad
 ElementTreeFrameTitle=Elements
-# The following string should NOT be translated: ViewportBackingStore
-ViewportBackingStore=false
-
-# menubar definition
-#
-# Each of the strings that follow form a key to be 
-# used to the actual menu definition.
-
-# The following string should NOT be translated: menubar
-menubar=file edit debug
 
 # file Menu definition
 #
@@ -24,8 +14,6 @@ menubar=file edit debug
 # save ->  Notepad.saveAction
 # exit ->  Notepad.exitAction
 
-# The following string should NOT be translated: file
-file=new open save - exit
 fileLabel=File
 openLabel=Open
 openImage=resources/open.gif
@@ -42,38 +30,22 @@ exitLabel=Exit
 # copy  -> JTextComponent.copyAction
 # paste -> JTextComponent.pasteAction
 
-# The following string should NOT be translated: edit
-edit=cut copy paste - undo redo
 editLabel=Edit
 cutLabel=Cut
-# The following string should NOT be translated: cutAction
-cutAction=cut-to-clipboard
 cutImage=resources/cut.gif
 copyLabel=Copy
-# The following string should NOT be translated: copyAction
-copyAction=copy-to-clipboard
 copyImage=resources/copy.gif
 pasteLabel=Paste
-# The following string should NOT be translated: pasteAction
-pasteAction=paste-from-clipboard
 pasteImage=resources/paste.gif
 undoLabel=Undo
-# The following string should NOT be translated: undoAction
-undoAction=Undo
 redoLabel=Redo
-# The following string should NOT be translated: redoAction
-redoAction=Redo
 
 #
 # debug Menu definition
 #
 
-# The following string should NOT be translated: debug
-debug=dump showElementTree
 debugLabel=Debug
 dumpLabel=Dump model to System.err
-# The following string should NOT be translated: dumpAction
-dumpAction=dump-model
 showElementTreeLabel=Show Elements
 
 # toolbar definition
@@ -83,8 +55,6 @@ showElementTreeLabel=Show Elements
 # are of course sharable, and in this case are shared
 # with the menu items.
 
-# The following string should NOT be translated: toolbar
-toolbar=new open save - cut copy paste
 newTooltip=Create a new file
 openTooltip=Open a file
 saveTooltip=Save to a file
diff --git a/jdk/src/share/demo/jfc/Notepad/resources/system.properties b/jdk/src/share/demo/jfc/Notepad/resources/system.properties
new file mode 100644
index 00000000000..a6f8786d099
--- /dev/null
+++ b/jdk/src/share/demo/jfc/Notepad/resources/system.properties
@@ -0,0 +1,12 @@
+#
+# Non-translatable properties for Notepad example
+
+ViewportBackingStore=false
+
+cutAction=cut-to-clipboard
+copyAction=copy-to-clipboard
+pasteAction=paste-from-clipboard
+undoAction=Undo
+redoAction=Redo
+dumpAction=dump-model
+

From b963b0bcc405ec5ed27a99a454249535ce3421d0 Mon Sep 17 00:00:00 2001
From: Oleg Pekhovskiy 
Date: Fri, 4 May 2012 18:42:08 +0400
Subject: [PATCH 016/463] 7146237:
 closed/java/awt/Focus/SetFocusTraversalKeysTest/SetFocusTraversalTest.html
 failed since 1.8.0b19

Reviewed-by: art, anthony
---
 jdk/src/share/classes/java/awt/Component.java |  6 +-
 jdk/src/share/classes/java/awt/Container.java |  6 +-
 .../java/awt/KeyboardFocusManager.java        | 89 +++++++++----------
 .../share/classes/javax/swing/JComponent.java |  6 +-
 4 files changed, 53 insertions(+), 54 deletions(-)

diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java
index 63fe2a80be9..00d363c1162 100644
--- a/jdk/src/share/classes/java/awt/Component.java
+++ b/jdk/src/share/classes/java/awt/Component.java
@@ -7169,6 +7169,9 @@ public abstract class Component implements ImageObserver, MenuContainer,
      * Set from its parent. If all ancestors of this Component have null
      * specified for the Set, then the current KeyboardFocusManager's default
      * Set is used.
+     * 

+ * This method may throw a {@code ClassCastException} if any {@code Object} + * in {@code keystrokes} is not an {@code AWTKeyStroke}. * * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or @@ -7182,8 +7185,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes - * contains null, or if any Object in keystrokes is not an - * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, + * contains null, or if any keystroke represents a KEY_TYPED event, * or if any keystroke already maps to another focus traversal * operation for this Component * @since 1.4 diff --git a/jdk/src/share/classes/java/awt/Container.java b/jdk/src/share/classes/java/awt/Container.java index 03b0f7faa04..99cbdaff124 100644 --- a/jdk/src/share/classes/java/awt/Container.java +++ b/jdk/src/share/classes/java/awt/Container.java @@ -3093,6 +3093,9 @@ public class Container extends Component { * Set from its parent. If all ancestors of this Container have null * specified for the Set, then the current KeyboardFocusManager's default * Set is used. + *

+ * This method may throw a {@code ClassCastException} if any {@code Object} + * in {@code keystrokes} is not an {@code AWTKeyStroke}. * * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, @@ -3109,8 +3112,7 @@ public class Container extends Component { * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, or if keystrokes - * contains null, or if any Object in keystrokes is not an - * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, + * contains null, or if any keystroke represents a KEY_TYPED event, * or if any keystroke already maps to another focus traversal * operation for this Container * @since 1.4 diff --git a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java index 3ccf5b70d36..7b8b9f41e25 100644 --- a/jdk/src/share/classes/java/awt/KeyboardFocusManager.java +++ b/jdk/src/share/classes/java/awt/KeyboardFocusManager.java @@ -991,12 +991,12 @@ public abstract class KeyboardFocusManager /** * Sets the default focus traversal keys for a given traversal operation. - * This traversal key Set will be in effect on all - * Windows that have no such Set of - * their own explicitly defined. This Set will also be - * inherited, recursively, by any child Component of - * those Windows that has - * no such Set of its own explicitly defined. + * This traversal key {@code Set} will be in effect on all + * {@code Window}s that have no such {@code Set} of + * their own explicitly defined. This {@code Set} will also be + * inherited, recursively, by any child {@code Component} of + * those {@code Windows} that has + * no such {@code Set} of its own explicitly defined. *

* The default values for the default focus traversal keys are * implementation-dependent. Sun recommends that all implementations for a @@ -1011,66 +1011,67 @@ public abstract class KeyboardFocusManager * Default * * - * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS + * {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS} * Normal forward keyboard traversal - * TAB on KEY_PRESSED, - * CTRL-TAB on KEY_PRESSED + * {@code TAB} on {@code KEY_PRESSED}, + * {@code CTRL-TAB} on {@code KEY_PRESSED} * * - * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS + * {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS} * Normal reverse keyboard traversal - * SHIFT-TAB on KEY_PRESSED, - * CTRL-SHIFT-TAB on KEY_PRESSED + * {@code SHIFT-TAB} on {@code KEY_PRESSED}, + * {@code CTRL-SHIFT-TAB} on {@code KEY_PRESSED} * * - * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS + * {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS} * Go up one focus traversal cycle * none * * - * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS + * {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS} * Go down one focus traversal cycle * none * * * - * To disable a traversal key, use an empty Set; - * Collections.EMPTY_SET is recommended. + * To disable a traversal key, use an empty {@code Set}; + * {@code Collections.EMPTY_SET} is recommended. *

- * Using the AWTKeyStroke API, client code can + * Using the {@code AWTKeyStroke} API, client code can * specify on which of two - * specific KeyEvents, KEY_PRESSED or - * KEY_RELEASED, the focus traversal operation will - * occur. Regardless of which KeyEvent is specified, - * however, all KeyEvents related to the focus - * traversal key, including the associated KEY_TYPED + * specific {@code KeyEvent}s, {@code KEY_PRESSED} or + * {@code KEY_RELEASED}, the focus traversal operation will + * occur. Regardless of which {@code KeyEvent} is specified, + * however, all {@code KeyEvent}s related to the focus + * traversal key, including the associated {@code KEY_TYPED} * event, will be consumed, and will not be dispatched - * to any Component. It is a runtime error to - * specify a KEY_TYPED event as + * to any {@code Component}. It is a runtime error to + * specify a {@code KEY_TYPED} event as * mapping to a focus traversal operation, or to map the same event to * multiple default focus traversal operations. + *

+ * This method may throw a {@code ClassCastException} if any {@code Object} + * in {@code keystrokes} is not an {@code AWTKeyStroke}. * * @param id one of - * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or - * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS - * @param keystrokes the Set of AWTKeyStrokes for the + * {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS}, + * {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS}, + * {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}, or + * {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS} + * @param keystrokes the Set of {@code AWTKeyStroke}s for the * specified operation * @see #getDefaultFocusTraversalKeys * @see Component#setFocusTraversalKeys * @see Component#getFocusTraversalKeys * @throws IllegalArgumentException if id is not one of - * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, - * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or - * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, - * or if keystrokes is null, - * or if keystrokes contains null, - * or if any Object in - * keystrokes is not an AWTKeyStroke, + * {@code KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS}, + * {@code KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS}, + * {@code KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS}, or + * {@code KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS}, + * or if keystrokes is {@code null}, + * or if keystrokes contains {@code null}, * or if any keystroke - * represents a KEY_TYPED event, + * represents a {@code KEY_TYPED} event, * or if any keystroke already maps * to another default focus traversal operation * @beaninfo @@ -1090,20 +1091,12 @@ public abstract class KeyboardFocusManager Set oldKeys; synchronized (this) { - for (Iterator iter = keystrokes.iterator(); iter.hasNext(); ) { - Object obj = iter.next(); + for (AWTKeyStroke keystroke : keystrokes) { - if (obj == null) { + if (keystroke == null) { throw new IllegalArgumentException("cannot set null focus traversal key"); } - // Fix for 6195831: - //According to javadoc this method should throw IAE instead of ClassCastException - if (!(obj instanceof AWTKeyStroke)) { - throw new IllegalArgumentException("object is expected to be AWTKeyStroke"); - } - AWTKeyStroke keystroke = (AWTKeyStroke)obj; - if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) { throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events"); } diff --git a/jdk/src/share/classes/javax/swing/JComponent.java b/jdk/src/share/classes/javax/swing/JComponent.java index 78bc5c4f648..83f88bfbfdc 100644 --- a/jdk/src/share/classes/javax/swing/JComponent.java +++ b/jdk/src/share/classes/javax/swing/JComponent.java @@ -4148,6 +4148,9 @@ public abstract class JComponent extends Container implements Serializable, * Refer to * {@link java.awt.Component#setFocusTraversalKeys} * for a complete description of this method. + *

+ * This method may throw a {@code ClassCastException} if any {@code Object} + * in {@code keystrokes} is not an {@code AWTKeyStroke}. * * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or @@ -4160,8 +4163,7 @@ public abstract class JComponent extends Container implements Serializable, * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, or * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or if keystrokes - * contains null, or if any Object in keystrokes is not an - * AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, + * contains null, or if any keystroke represents a KEY_TYPED event, * or if any keystroke already maps to another focus traversal * operation for this Component * @since 1.5 From 324e987e82197c1043b57846e0a7c4f122e1a82d Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Fri, 4 May 2012 07:55:51 -0700 Subject: [PATCH 017/463] 7166010: (javac) JavacMessager incorrectly restores log source file Reviewed-by: jjg --- .../tools/javac/processing/JavacMessager.java | 6 +- .../processing/messager/MessagerDiags.java | 131 ++++++++++++++++++ 2 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 langtools/test/tools/javac/processing/messager/MessagerDiags.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java index eeeb0953609..bc6acc1a096 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java +++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -99,6 +99,7 @@ public class JavacMessager implements Messager { if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { + // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } @@ -131,7 +132,8 @@ public class JavacMessager implements Messager { break; } } finally { - if (oldSource != null) + // reinstate the saved version, only if it was saved earlier + if (newSource != null) log.useSource(oldSource); } } diff --git a/langtools/test/tools/javac/processing/messager/MessagerDiags.java b/langtools/test/tools/javac/processing/messager/MessagerDiags.java new file mode 100644 index 00000000000..6f333a36090 --- /dev/null +++ b/langtools/test/tools/javac/processing/messager/MessagerDiags.java @@ -0,0 +1,131 @@ +/* + * 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 + * @bug 7166010 + * @summary warnings printed by annotation processors uses incorrect source + */ +import com.sun.source.util.JavacTask; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Messager; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticCollector; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +import static javax.tools.Diagnostic.Kind.*; +import static javax.tools.JavaFileObject.Kind.*; + +@SupportedSourceVersion(SourceVersion.RELEASE_6) +@SupportedAnnotationTypes("*") +public class MessagerDiags extends AbstractProcessor { + static final String CNAME = "Test"; + static final String TEST_JAVA = CNAME + ".java"; + static final String TEST_JAVA_URI_NAME = "myfo:/" + TEST_JAVA; + static final String WRN_NO_SOURCE = "warning without source"; + static final String WRN_WITH_SOURCE = "warning with source"; + static final String NONE = ""; + static final String[] EXPECTED = { NONE + ":-1--1:" + WRN_NO_SOURCE, + TEST_JAVA + ":0-13:" + WRN_WITH_SOURCE, + NONE + ":-1--1:" + WRN_NO_SOURCE + }; + + @Override + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + Messager messager = processingEnv.getMessager(); + for (Element e : roundEnv.getRootElements()) { + messager.printMessage(WARNING, WRN_NO_SOURCE); + messager.printMessage(WARNING, WRN_WITH_SOURCE, e); + messager.printMessage(WARNING, WRN_NO_SOURCE); + } + return false; + } + + public static void main(String... args) throws IOException { + final String bootPath = System.getProperty("sun.boot.class.path"); + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); + assert tool != null; + + DiagnosticCollector dc = new DiagnosticCollector<>(); + List options = new LinkedList<>(); + options.addAll(Arrays.asList("-bootclasspath", bootPath, + "-source", "1.6", "-classpath", + System.getProperty("java.class.path"))); + options.addAll(Arrays.asList("-processor", + MessagerDiags.class.getName())); + JavacTask ct = (JavacTask)tool.getTask(null, null, dc, options, null, + Arrays.asList(new MyFileObject("class " + CNAME + " {}"))); + ct.analyze(); + + List obtainedErrors = new ArrayList<>(); + + for (Diagnostic d : dc.getDiagnostics()) { + String dSource; + if (d.getSource() != null) { + dSource = d.getSource().toUri().getPath(); + dSource = dSource.substring(dSource.lastIndexOf('/') + 1); + } else { + dSource = NONE; + } + obtainedErrors.add(dSource + ":" + d.getStartPosition() + "-" + + d.getEndPosition() + ":" + d.getMessage(null)); + } + List expectedErrors = Arrays.asList(EXPECTED); + if (!expectedErrors.equals(obtainedErrors)) { + System.err.println("Expected: " + expectedErrors); + System.err.println("Obtained: " + obtainedErrors); + throw new AssertionError("Messages don't match"); + } + } + + static class MyFileObject extends SimpleJavaFileObject { + private String text; + public MyFileObject(String text) { + super(URI.create(TEST_JAVA_URI_NAME), SOURCE); + this.text = text; + } + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return text; + } + } +} From bf549e93b93b1c0e0af3cf9e6517c7eb0b89aabb Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Fri, 4 May 2012 21:25:08 +0400 Subject: [PATCH 018/463] 7147055: [macosx] Cursors are changing over a blocked window; also blinking Reviewed-by: art, kizune --- jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java b/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java index 1c34353c7b9..de1b537856a 100644 --- a/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java +++ b/jdk/src/macosx/classes/sun/lwawt/LWCursorManager.java @@ -88,20 +88,20 @@ public abstract class LWCursorManager { } else { cursor = (c != null) ? c.getCursor() : null; } - // TODO: default cursor for modal blocked windows setCursor(cursor); } /** * Returns the first visible, enabled and showing component under cursor. + * Returns null for modal blocked windows. * * @param cursorPos Current cursor position. - * @return Component + * @return Component or null. */ private static final Component findComponent(final Point cursorPos) { final LWComponentPeer peer = LWWindowPeer.getPeerUnderCursor(); Component c = null; - if (peer != null) { + if (peer != null && peer.getWindowPeerOrSelf().getBlocker() == null) { c = peer.getTarget(); if (c instanceof Container) { final Point p = peer.getLocationOnScreen(); From 2f8d099c20523e53c8435fdb43f9e3de6d3d1d92 Mon Sep 17 00:00:00 2001 From: Knut Anders Hatlen Date: Fri, 4 May 2012 16:00:47 -0400 Subject: [PATCH 019/463] 7166598: FilteredRowSetImpl can result in Invalid Cursor Position Reviewed-by: lancea --- jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java b/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java index a18c0ac10bd..20c2743ee4b 100644 --- a/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java +++ b/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java @@ -128,7 +128,7 @@ public class FilteredRowSetImpl extends WebRowSetImpl implements Serializable, C for(int rows=this.getRow(); rows<=this.size();rows++) { bool = super.internalNext(); - if( p == null) { + if( !bool || p == null) { return bool; } if(p.evaluate(this)){ From 7ae15519b1b4b8cbae6deec1da5d6ffb5717ee01 Mon Sep 17 00:00:00 2001 From: Xue-Lei Andrew Fan Date: Fri, 4 May 2012 17:28:27 -0700 Subject: [PATCH 020/463] 7153184: NullPointerException when calling SSLEngineImpl.getSupportedCipherSuites Reviewed-by: weijun --- .../sun/security/ssl/SSLContextImpl.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java b/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java index 9814f9f5010..bb57a61f828 100644 --- a/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java +++ b/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java @@ -267,12 +267,15 @@ public abstract class SSLContextImpl extends SSLContextSpi { // Get suported CipherSuiteList. CipherSuiteList getSuportedCipherSuiteList() { - // Clear cache of available ciphersuites. - clearAvailableCache(); + // The maintenance of cipher suites needs to be synchronized. + synchronized (this) { + // Clear cache of available ciphersuites. + clearAvailableCache(); - if (supportedCipherSuiteList == null) { - supportedCipherSuiteList = - getApplicableCipherSuiteList(getSuportedProtocolList(), false); + if (supportedCipherSuiteList == null) { + supportedCipherSuiteList = getApplicableCipherSuiteList( + getSuportedProtocolList(), false); + } } return supportedCipherSuiteList; @@ -280,20 +283,29 @@ public abstract class SSLContextImpl extends SSLContextSpi { // Get default CipherSuiteList. CipherSuiteList getDefaultCipherSuiteList(boolean roleIsServer) { - // Clear cache of available ciphersuites. - clearAvailableCache(); - if (roleIsServer) { - if (defaultServerCipherSuiteList == null) { - defaultServerCipherSuiteList = getApplicableCipherSuiteList( + // The maintenance of cipher suites needs to be synchronized. + synchronized (this) { + // Clear cache of available ciphersuites. + clearAvailableCache(); + + if (defaultServerCipherSuiteList == null) { + defaultServerCipherSuiteList = getApplicableCipherSuiteList( getDefaultProtocolList(true), true); + } } return defaultServerCipherSuiteList; } else { - if (defaultClientCipherSuiteList == null) { - defaultClientCipherSuiteList = getApplicableCipherSuiteList( + // The maintenance of cipher suites needs to be synchronized + synchronized (this) { + // Clear cache of available ciphersuites. + clearAvailableCache(); + + if (defaultClientCipherSuiteList == null) { + defaultClientCipherSuiteList = getApplicableCipherSuiteList( getDefaultProtocolList(false), true); + } } return defaultClientCipherSuiteList; @@ -364,8 +376,11 @@ public abstract class SSLContextImpl extends SSLContextSpi { * Clear cache of available ciphersuites. If we support all ciphers * internally, there is no need to clear the cache and calling this * method has no effect. + * + * Note that every call to clearAvailableCache() and the maintenance of + * cipher suites need to be synchronized with this instance. */ - synchronized void clearAvailableCache() { + private void clearAvailableCache() { if (CipherSuite.DYNAMIC_AVAILABILITY) { supportedCipherSuiteList = null; defaultServerCipherSuiteList = null; From 703f08dfe8d36de946101e69a53858a08b3acf8a Mon Sep 17 00:00:00 2001 From: Sean Chou Date: Mon, 7 May 2012 16:43:16 +0800 Subject: [PATCH 021/463] 7166048: Remove the embeded epoll data structure Reviewed-by: alanb --- .../native/sun/nio/ch/EPollArrayWrapper.c | 60 ++----------------- 1 file changed, 5 insertions(+), 55 deletions(-) diff --git a/jdk/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c b/jdk/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c index 3d4f05100d1..7f7a3e82690 100644 --- a/jdk/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c +++ b/jdk/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c @@ -30,40 +30,10 @@ #include "sun_nio_ch_EPollArrayWrapper.h" -#include #include #include #include - -#ifdef __cplusplus -extern "C" { -#endif - -/* epoll_wait(2) man page */ - -typedef union epoll_data { - void *ptr; - int fd; - __uint32_t u32; - __uint64_t u64; -} epoll_data_t; - - -/* x86-64 has same alignment as 32-bit */ -#ifdef __x86_64__ -#define EPOLL_PACKED __attribute__((packed)) -#else -#define EPOLL_PACKED -#endif - -struct epoll_event { - __uint32_t events; /* Epoll events */ - epoll_data_t data; /* User data variable */ -} EPOLL_PACKED; - -#ifdef __cplusplus -} -#endif +#include #define RESTARTABLE(_cmd, _result) do { \ do { \ @@ -71,18 +41,6 @@ struct epoll_event { } while((_result == -1) && (errno == EINTR)); \ } while(0) -/* - * epoll event notification is new in 2.6 kernel. As the offical build - * platform for the JDK is on a 2.4-based distribution then we must - * obtain the addresses of the epoll functions dynamically. - */ -typedef int (*epoll_create_t)(int size); -typedef int (*epoll_ctl_t) (int epfd, int op, int fd, struct epoll_event *event); -typedef int (*epoll_wait_t) (int epfd, struct epoll_event *events, int maxevents, int timeout); - -static epoll_create_t epoll_create_func; -static epoll_ctl_t epoll_ctl_func; -static epoll_wait_t epoll_wait_func; static int iepoll(int epfd, struct epoll_event *events, int numfds, jlong timeout) @@ -96,7 +54,7 @@ iepoll(int epfd, struct epoll_event *events, int numfds, jlong timeout) start = t.tv_sec * 1000 + t.tv_usec / 1000; for (;;) { - int res = (*epoll_wait_func)(epfd, events, numfds, timeout); + int res = epoll_wait(epfd, events, numfds, timeout); if (res < 0 && errno == EINTR) { if (remaining >= 0) { gettimeofday(&t, NULL); @@ -117,14 +75,6 @@ iepoll(int epfd, struct epoll_event *events, int numfds, jlong timeout) JNIEXPORT void JNICALL Java_sun_nio_ch_EPollArrayWrapper_init(JNIEnv *env, jclass this) { - epoll_create_func = (epoll_create_t) dlsym(RTLD_DEFAULT, "epoll_create"); - epoll_ctl_func = (epoll_ctl_t) dlsym(RTLD_DEFAULT, "epoll_ctl"); - epoll_wait_func = (epoll_wait_t) dlsym(RTLD_DEFAULT, "epoll_wait"); - - if ((epoll_create_func == NULL) || (epoll_ctl_func == NULL) || - (epoll_wait_func == NULL)) { - JNU_ThrowInternalError(env, "unable to get address of epoll functions, pre-2.6 kernel?"); - } } JNIEXPORT jint JNICALL @@ -134,7 +84,7 @@ Java_sun_nio_ch_EPollArrayWrapper_epollCreate(JNIEnv *env, jobject this) * epoll_create expects a size as a hint to the kernel about how to * dimension internal structures. We can't predict the size in advance. */ - int epfd = (*epoll_create_func)(256); + int epfd = epoll_create(256); if (epfd < 0) { JNU_ThrowIOExceptionWithLastError(env, "epoll_create failed"); } @@ -173,7 +123,7 @@ Java_sun_nio_ch_EPollArrayWrapper_epollCtl(JNIEnv *env, jobject this, jint epfd, event.events = events; event.data.fd = fd; - RESTARTABLE((*epoll_ctl_func)(epfd, (int)opcode, (int)fd, &event), res); + RESTARTABLE(epoll_ctl(epfd, (int)opcode, (int)fd, &event), res); /* * A channel may be registered with several Selectors. When each Selector @@ -199,7 +149,7 @@ Java_sun_nio_ch_EPollArrayWrapper_epollWait(JNIEnv *env, jobject this, int res; if (timeout <= 0) { /* Indefinite or no wait */ - RESTARTABLE((*epoll_wait_func)(epfd, events, numfds, timeout), res); + RESTARTABLE(epoll_wait(epfd, events, numfds, timeout), res); } else { /* Bounded wait; bounded restarts */ res = iepoll(epfd, events, numfds, timeout); } From fd928bc1ef63ffc6288f83e520ab794814093d4a Mon Sep 17 00:00:00 2001 From: Rob McKenna Date: Mon, 7 May 2012 13:34:19 +0100 Subject: [PATCH 022/463] 7166687: InetAddress.getLocalHost().getHostName() returns FQDN Reviewed-by: chegar --- jdk/src/solaris/native/java/net/Inet6AddressImpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c index e612131b95c..608f3c595d2 100644 --- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c +++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -73,7 +73,7 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { } else { // ensure null-terminated hostname[NI_MAXHOST] = '\0'; -#if defined(__linux__) && defined(_ALLBSD_SOURCE) +#if defined(__linux__) || defined(_ALLBSD_SOURCE) /* On Linux/FreeBSD gethostname() says "host.domain.sun.com". On * Solaris gethostname() says "host", so extra work is needed. */ From 828158fb8d9d71c96a40b66d5d80cfb6d1b35aee Mon Sep 17 00:00:00 2001 From: David Holmes Date: Tue, 8 May 2012 02:59:10 -0400 Subject: [PATCH 023/463] 7103570: AtomicIntegerFieldUpdater does not work when SecurityManager is installed Perform class.getField inside a doPrivileged block Reviewed-by: chegar, psandoz --- .../atomic/AtomicIntegerFieldUpdater.java | 44 +++- .../atomic/AtomicLongFieldUpdater.java | 62 +++++- .../atomic/AtomicReferenceFieldUpdater.java | 66 ++++-- .../concurrent/atomic/AtomicUpdaters.java | 189 ++++++++++++++++++ 4 files changed, 332 insertions(+), 29 deletions(-) create mode 100644 jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java diff --git a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java index 9f4fee4aa84..dc26f4c0ba7 100644 --- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java +++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java @@ -35,7 +35,11 @@ package java.util.concurrent.atomic; import sun.misc.Unsafe; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; /** * A reflection-based utility that enables atomic updates to @@ -67,7 +71,9 @@ public abstract class AtomicIntegerFieldUpdater { * @throws IllegalArgumentException if the field is not a * volatile integer type * @throws RuntimeException with a nested reflection-based - * exception if the class does not hold field or is the wrong type + * exception if the class does not hold field or is the wrong type, + * or the field is inaccessible to the caller according to Java language + * access control */ public static AtomicIntegerFieldUpdater newUpdater(Class tclass, String fieldName) { return new AtomicIntegerFieldUpdaterImpl(tclass, fieldName); @@ -267,17 +273,29 @@ public abstract class AtomicIntegerFieldUpdater { private final Class tclass; private final Class cclass; - AtomicIntegerFieldUpdaterImpl(Class tclass, String fieldName) { + AtomicIntegerFieldUpdaterImpl(final Class tclass, final String fieldName) { Field field = null; Class caller = null; int modifiers = 0; try { - field = tclass.getDeclaredField(fieldName); + field = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Field run() throws NoSuchFieldException { + return tclass.getDeclaredField(fieldName); + } + }); caller = sun.reflect.Reflection.getCallerClass(3); modifiers = field.getModifiers(); sun.reflect.misc.ReflectUtil.ensureMemberAccess( caller, tclass, null, modifiers); - sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + ClassLoader cl = tclass.getClassLoader(); + ClassLoader ccl = caller.getClassLoader(); + if ((ccl != null) && (ccl != cl) && + ((cl == null) || !isAncestor(cl, ccl))) { + sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + } + } catch (PrivilegedActionException pae) { + throw new RuntimeException(pae.getException()); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -295,6 +313,22 @@ public abstract class AtomicIntegerFieldUpdater { offset = unsafe.objectFieldOffset(field); } + /** + * Returns true if the second classloader can be found in the first + * classloader's delegation chain. + * Equivalent to the inaccessible: first.isAncestor(second). + */ + private static boolean isAncestor(ClassLoader first, ClassLoader second) { + ClassLoader acl = first; + do { + acl = acl.getParent(); + if (second == acl) { + return true; + } + } while (acl != null); + return false; + } + private void fullCheck(T obj) { if (!tclass.isInstance(obj)) throw new ClassCastException(); diff --git a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java index ccc5acbfe21..3311aecdbfb 100644 --- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java +++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java @@ -35,7 +35,11 @@ package java.util.concurrent.atomic; import sun.misc.Unsafe; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; /** * A reflection-based utility that enables atomic updates to @@ -67,7 +71,9 @@ public abstract class AtomicLongFieldUpdater { * @throws IllegalArgumentException if the field is not a * volatile long type. * @throws RuntimeException with a nested reflection-based - * exception if the class does not hold field or is the wrong type. + * exception if the class does not hold field or is the wrong type, + * or the field is inaccessible to the caller according to Java language + * access control */ public static AtomicLongFieldUpdater newUpdater(Class tclass, String fieldName) { if (AtomicLong.VM_SUPPORTS_LONG_CAS) @@ -267,17 +273,29 @@ public abstract class AtomicLongFieldUpdater { private final Class tclass; private final Class cclass; - CASUpdater(Class tclass, String fieldName) { + CASUpdater(final Class tclass, final String fieldName) { Field field = null; Class caller = null; int modifiers = 0; try { - field = tclass.getDeclaredField(fieldName); + field = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Field run() throws NoSuchFieldException { + return tclass.getDeclaredField(fieldName); + } + }); caller = sun.reflect.Reflection.getCallerClass(3); modifiers = field.getModifiers(); sun.reflect.misc.ReflectUtil.ensureMemberAccess( caller, tclass, null, modifiers); - sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + ClassLoader cl = tclass.getClassLoader(); + ClassLoader ccl = caller.getClassLoader(); + if ((ccl != null) && (ccl != cl) && + ((cl == null) || !isAncestor(cl, ccl))) { + sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + } + } catch (PrivilegedActionException pae) { + throw new RuntimeException(pae.getException()); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -350,17 +368,29 @@ public abstract class AtomicLongFieldUpdater { private final Class tclass; private final Class cclass; - LockedUpdater(Class tclass, String fieldName) { + LockedUpdater(final Class tclass, final String fieldName) { Field field = null; Class caller = null; int modifiers = 0; try { - field = tclass.getDeclaredField(fieldName); + field = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Field run() throws NoSuchFieldException { + return tclass.getDeclaredField(fieldName); + } + }); caller = sun.reflect.Reflection.getCallerClass(3); modifiers = field.getModifiers(); sun.reflect.misc.ReflectUtil.ensureMemberAccess( caller, tclass, null, modifiers); - sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + ClassLoader cl = tclass.getClassLoader(); + ClassLoader ccl = caller.getClassLoader(); + if ((ccl != null) && (ccl != cl) && + ((cl == null) || !isAncestor(cl, ccl))) { + sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + } + } catch (PrivilegedActionException pae) { + throw new RuntimeException(pae.getException()); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -433,4 +463,20 @@ public abstract class AtomicLongFieldUpdater { ); } } + + /** + * Returns true if the second classloader can be found in the first + * classloader's delegation chain. + * Equivalent to the inaccessible: first.isAncestor(second). + */ + private static boolean isAncestor(ClassLoader first, ClassLoader second) { + ClassLoader acl = first; + do { + acl = acl.getParent(); + if (second == acl) { + return true; + } + } while (acl != null); + return false; + } } diff --git a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java index f2e0118aae7..bba703e67ec 100644 --- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java +++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java @@ -35,7 +35,11 @@ package java.util.concurrent.atomic; import sun.misc.Unsafe; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; /** * A reflection-based utility that enables atomic updates to @@ -86,7 +90,9 @@ public abstract class AtomicReferenceFieldUpdater { * @return the updater * @throws IllegalArgumentException if the field is not a volatile reference type. * @throws RuntimeException with a nested reflection-based - * exception if the class does not hold field or is the wrong type. + * exception if the class does not hold field or is the wrong type, + * or the field is inaccessible to the caller according to Java language + * access control */ public static AtomicReferenceFieldUpdater newUpdater(Class tclass, Class vclass, String fieldName) { return new AtomicReferenceFieldUpdaterImpl(tclass, @@ -197,21 +203,33 @@ public abstract class AtomicReferenceFieldUpdater { * screenings fail. */ - AtomicReferenceFieldUpdaterImpl(Class tclass, + AtomicReferenceFieldUpdaterImpl(final Class tclass, Class vclass, - String fieldName) { + final String fieldName) { Field field = null; Class fieldClass = null; Class caller = null; int modifiers = 0; try { - field = tclass.getDeclaredField(fieldName); + field = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Field run() throws NoSuchFieldException { + return tclass.getDeclaredField(fieldName); + } + }); caller = sun.reflect.Reflection.getCallerClass(3); modifiers = field.getModifiers(); sun.reflect.misc.ReflectUtil.ensureMemberAccess( - caller, tclass, null, modifiers); - sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + caller, tclass, null, modifiers); + ClassLoader cl = tclass.getClassLoader(); + ClassLoader ccl = caller.getClassLoader(); + if ((ccl != null) && (ccl != cl) && + ((cl == null) || !isAncestor(cl, ccl))) { + sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + } fieldClass = field.getType(); + } catch (PrivilegedActionException pae) { + throw new RuntimeException(pae.getException()); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -232,6 +250,22 @@ public abstract class AtomicReferenceFieldUpdater { offset = unsafe.objectFieldOffset(field); } + /** + * Returns true if the second classloader can be found in the first + * classloader's delegation chain. + * Equivalent to the inaccessible: first.isAncestor(second). + */ + private static boolean isAncestor(ClassLoader first, ClassLoader second) { + ClassLoader acl = first; + do { + acl = acl.getParent(); + if (second == acl) { + return true; + } + } while (acl != null); + return false; + } + void targetCheck(T obj) { if (!tclass.isInstance(obj)) throw new ClassCastException(); @@ -281,7 +315,7 @@ public abstract class AtomicReferenceFieldUpdater { } @SuppressWarnings("unchecked") - public V get(T obj) { + public V get(T obj) { if (obj == null || obj.getClass() != tclass || cclass != null) targetCheck(obj); return (V)unsafe.getObjectVolatile(obj, offset); @@ -292,14 +326,14 @@ public abstract class AtomicReferenceFieldUpdater { return; } throw new RuntimeException( - new IllegalAccessException("Class " + - cclass.getName() + - " can not access a protected member of class " + - tclass.getName() + - " using an instance of " + - obj.getClass().getName() - ) - ); + new IllegalAccessException("Class " + + cclass.getName() + + " can not access a protected member of class " + + tclass.getName() + + " using an instance of " + + obj.getClass().getName() + ) + ); } } } diff --git a/jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java b/jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java new file mode 100644 index 00000000000..62d066914d2 --- /dev/null +++ b/jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java @@ -0,0 +1,189 @@ +/* + * 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 7103570 + * @author David Holmes + * @run main/othervm AtomicUpdaters + * @run main/othervm AtomicUpdaters UseSM + * @summary Checks the (in)ability to create field updaters for differently + * accessible fields in different locations with/without a security + * manager + */ +import java.util.concurrent.atomic.*; +import java.lang.reflect.*; +import java.security.AccessControlException; + +public class AtomicUpdaters { + enum TYPE { INT, LONG, REF } + + static class Config { + final Class clazz; + final String field; + final String access; + final boolean reflectOk; + final boolean updaterOk; + final String desc; + final TYPE type; + + Config(Class clazz, String field, String access, + boolean reflectOk, boolean updaterOk, String desc, TYPE type) { + this.clazz = clazz; + this.field = field; + this.access = access; + this.reflectOk = reflectOk; + this.updaterOk = updaterOk; + this.desc = desc; + this.type =type; + } + + public String toString() { + return desc + ": " + access + " " + clazz.getName() + "." + field; + } + } + + static Config[] tests; + + static void initTests(boolean hasSM) { + tests = new Config[] { + new Config(AtomicUpdaters.class, "pub_int", "public", true, true, "public int field of current class", TYPE.INT), + new Config(AtomicUpdaters.class, "priv_int", "private", true, true, "private int field of current class", TYPE.INT), + new Config(AtomicUpdaters.class, "pub_long", "public", true, true, "public long field of current class", TYPE.LONG), + new Config(AtomicUpdaters.class, "priv_long", "private", true, true, "private long field of current class", TYPE.LONG), + new Config(AtomicUpdaters.class, "pub_ref", "public", true, true, "public ref field of current class", TYPE.REF), + new Config(AtomicUpdaters.class, "priv_ref", "private", true, true, "private ref field of current class", TYPE.REF), + + // Would like to test a public volatile in a class in another + // package - but of course there aren't any + new Config(java.util.concurrent.atomic.AtomicInteger.class, "value", "private", hasSM ? false : true, false, "private int field of class in different package", TYPE.INT), + new Config(java.util.concurrent.atomic.AtomicLong.class, "value", "private", hasSM ? false : true, false, "private long field of class in different package", TYPE.LONG), + new Config(java.util.concurrent.atomic.AtomicReference.class, "value", "private", hasSM ? false : true, false, "private reference field of class in different package", TYPE.REF), + }; + } + + public volatile int pub_int; + private volatile int priv_int; + public volatile long pub_long; + private volatile long priv_long; + public volatile Object pub_ref; + private volatile Object priv_ref; + + + // This should be set dynamically at runtime using a System property, but + // ironically we get a SecurityException if we try to do that with a + // SecurityManager installed + static boolean verbose; + + public static void main(String[] args) throws Throwable { + boolean hasSM = false; + for (String arg : args) { + if ("-v".equals(arg)) { + verbose = true; + } + else if ("UseSM".equals(arg)) { + SecurityManager m = System.getSecurityManager(); + if (m != null) + throw new RuntimeException("No security manager should initially be installed"); + System.setSecurityManager(new java.lang.SecurityManager()); + hasSM = true; + } + else { + throw new IllegalArgumentException("Unexpected option: " + arg); + } + } + initTests(hasSM); + + int failures = 0; + + System.out.printf("Testing with%s a SecurityManager present\n", hasSM ? "" : "out"); + for (Config c : tests) { + System.out.println("Testing: " + c); + Error reflectionFailure = null; + Error updaterFailure = null; + Class clazz = c.clazz; + // See if we can reflectively access the field + System.out.println(" - testing getDeclaredField"); + try { + Field f = clazz.getDeclaredField(c.field); + if (!c.reflectOk) + reflectionFailure = new Error("Unexpected reflective access: " + c); + } + catch (AccessControlException e) { + if (c.reflectOk) + reflectionFailure = new Error("Unexpected reflective access failure: " + c, e); + else if (verbose) { + System.out.println("Got expected reflection exception: " + e); + e.printStackTrace(System.out); + } + } + + if (reflectionFailure != null) { + reflectionFailure.printStackTrace(System.out); + } + + // see if we can create an atomic updater for the field + Object u = null; + try { + switch (c.type) { + case INT: + System.out.println(" - testing AtomicIntegerFieldUpdater"); + u = AtomicIntegerFieldUpdater.newUpdater(clazz, c.field); + break; + case LONG: + System.out.println(" - testing AtomicLongFieldUpdater"); + u = AtomicLongFieldUpdater.newUpdater(clazz, c.field); + break; + case REF: + System.out.println(" - testing AtomicReferenceFieldUpdater"); + u = AtomicReferenceFieldUpdater.newUpdater(clazz, Object.class, c.field); + break; + } + + if (!c.updaterOk) + updaterFailure = new Error("Unexpected updater access: " + c); + } + catch (Exception e) { + if (c.updaterOk) + updaterFailure = new Error("Unexpected updater access failure: " + c, e); + else if (verbose) { + System.out.println("Got expected updater exception: " + e); + e.printStackTrace(System.out); + } + } + + if (updaterFailure != null) { + updaterFailure.printStackTrace(System.out); + } + + if (updaterFailure != null || reflectionFailure != null) { + failures++; + + } + } + + if (failures > 0) { + throw new Error("Some tests failed - see previous stacktraces"); + } + } +} From c8da8f2595f948524a869ff5928303a029ad9e98 Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Tue, 8 May 2012 10:57:13 -0700 Subject: [PATCH 024/463] 7014640: To add a metachar \R for line ending and character classes for vertical/horizontal ws \v \V \h \H Added propsoed constructs Reviewed-by: alanb --- .../classes/java/util/regex/Pattern.java | 140 +++++++++++++----- jdk/test/java/util/regex/RegExTest.java | 84 ++++++++++- 2 files changed, 189 insertions(+), 35 deletions(-) diff --git a/jdk/src/share/classes/java/util/regex/Pattern.java b/jdk/src/share/classes/java/util/regex/Pattern.java index 626d5b08657..6c32f6a30bb 100644 --- a/jdk/src/share/classes/java/util/regex/Pattern.java +++ b/jdk/src/share/classes/java/util/regex/Pattern.java @@ -152,15 +152,24 @@ import java.util.Arrays; * A digit: [0-9] * \D * A non-digit: [^0-9] + * \h + * A horizontal whitespace character: + * [ \t\xA0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000] + * \H + * A non-horizontal whitespace character: [^\h] * \s * A whitespace character: [ \t\n\x0B\f\r] * \S * A non-whitespace character: [^\s] + * \v + * A vertical whitespace character: [\n\x0B\f\r\x85\u2028\u2029] + * + * \V + * A non-vertical whitespace character: [^\v] * \w * A word character: [a-zA-Z_0-9] * \W * A non-word character: [^\w] - * *   * POSIX character classes (US-ASCII only) * @@ -244,6 +253,13 @@ import java.util.Arrays; * The end of the input * *   + * Linebreak matcher + * \R + * Any Unicode linebreak sequence, is equivalent to + * \u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029] + * + * + *   * Greedy quantifiers * * X? @@ -599,11 +615,9 @@ import java.util.Arrays; *

  • Noncharacter_Code_Point *
  • Assigned * - - *

    - * Predefined Character classes and POSIX character classes are in - * conformance with the recommendation of Annex C: Compatibility Properties + * The following Predefined Character classes and POSIX character classes + * are in conformance with the recommendation of Annex C: Compatibility Properties * of Unicode Regular Expression * , when {@link #UNICODE_CHARACTER_CLASS} flag is specified. *

    @@ -668,12 +682,6 @@ import java.util.Arrays; * *