From: <ls...@us...> - 2011-03-05 11:09:41
|
Revision: 5797 http://jnode.svn.sourceforge.net/jnode/?rev=5797&view=rev Author: lsantha Date: 2011-03-05 11:09:31 +0000 (Sat, 05 Mar 2011) Log Message: ----------- Integrating OpenJDK 6 b22. Modified Paths: -------------- classlib6/core/src/openjdk/java/java/awt/color/CMMException.java classlib6/core/src/openjdk/java/java/awt/color/ColorSpace.java classlib6/core/src/openjdk/java/java/awt/color/ICC_ColorSpace.java classlib6/core/src/openjdk/java/java/awt/color/ICC_Profile.java classlib6/core/src/openjdk/java/java/awt/color/ICC_ProfileGray.java classlib6/core/src/openjdk/java/java/awt/color/ICC_ProfileRGB.java classlib6/core/src/openjdk/java/java/awt/color/ProfileDataException.java classlib6/core/src/openjdk/java/java/awt/color/package.html classlib6/core/src/openjdk/java/java/awt/image/IndexColorModel.java classlib6/core/src/openjdk/java/java/beans/EventHandler.java classlib6/core/src/openjdk/java/java/beans/Introspector.java classlib6/core/src/openjdk/java/java/beans/MetaData.java classlib6/core/src/openjdk/java/java/beans/Statement.java classlib6/core/src/openjdk/java/java/math/BigDecimal.java classlib6/core/src/openjdk/java/java/math/BigInteger.java classlib6/core/src/openjdk/java/java/math/BitSieve.java classlib6/core/src/openjdk/java/java/math/MathContext.java classlib6/core/src/openjdk/java/java/math/MutableBigInteger.java classlib6/core/src/openjdk/java/java/math/SignedMutableBigInteger.java classlib6/core/src/openjdk/java/java/security/AccessControlException.java classlib6/core/src/openjdk/java/java/security/AlgorithmParameterGenerator.java classlib6/core/src/openjdk/java/java/security/AlgorithmParameterGeneratorSpi.java classlib6/core/src/openjdk/java/java/security/AlgorithmParameters.java classlib6/core/src/openjdk/java/java/security/AlgorithmParametersSpi.java classlib6/core/src/openjdk/java/java/security/AllPermission.java classlib6/core/src/openjdk/java/java/security/AuthProvider.java classlib6/core/src/openjdk/java/java/security/BasicPermission.java classlib6/core/src/openjdk/java/java/security/Certificate.java classlib6/core/src/openjdk/java/java/security/CodeSigner.java classlib6/core/src/openjdk/java/java/security/CodeSource.java classlib6/core/src/openjdk/java/java/security/DigestException.java classlib6/core/src/openjdk/java/java/security/DigestInputStream.java classlib6/core/src/openjdk/java/java/security/DigestOutputStream.java classlib6/core/src/openjdk/java/java/security/DomainCombiner.java classlib6/core/src/openjdk/java/java/security/GeneralSecurityException.java classlib6/core/src/openjdk/java/java/security/Guard.java classlib6/core/src/openjdk/java/java/security/GuardedObject.java classlib6/core/src/openjdk/java/java/security/Identity.java classlib6/core/src/openjdk/java/java/security/IdentityScope.java classlib6/core/src/openjdk/java/java/security/InvalidAlgorithmParameterException.java classlib6/core/src/openjdk/java/java/security/InvalidKeyException.java classlib6/core/src/openjdk/java/java/security/InvalidParameterException.java classlib6/core/src/openjdk/java/java/security/Key.java classlib6/core/src/openjdk/java/java/security/KeyException.java classlib6/core/src/openjdk/java/java/security/KeyFactory.java classlib6/core/src/openjdk/java/java/security/KeyFactorySpi.java classlib6/core/src/openjdk/java/java/security/KeyManagementException.java classlib6/core/src/openjdk/java/java/security/KeyPair.java classlib6/core/src/openjdk/java/java/security/KeyPairGenerator.java classlib6/core/src/openjdk/java/java/security/KeyPairGeneratorSpi.java classlib6/core/src/openjdk/java/java/security/KeyRep.java classlib6/core/src/openjdk/java/java/security/KeyStore.java classlib6/core/src/openjdk/java/java/security/KeyStoreException.java classlib6/core/src/openjdk/java/java/security/KeyStoreSpi.java classlib6/core/src/openjdk/java/java/security/MessageDigest.java classlib6/core/src/openjdk/java/java/security/MessageDigestSpi.java classlib6/core/src/openjdk/java/java/security/NoSuchAlgorithmException.java classlib6/core/src/openjdk/java/java/security/NoSuchProviderException.java classlib6/core/src/openjdk/java/java/security/Permission.java classlib6/core/src/openjdk/java/java/security/PermissionCollection.java classlib6/core/src/openjdk/java/java/security/Permissions.java classlib6/core/src/openjdk/java/java/security/Policy.java classlib6/core/src/openjdk/java/java/security/Principal.java classlib6/core/src/openjdk/java/java/security/PrivateKey.java classlib6/core/src/openjdk/java/java/security/PrivilegedAction.java classlib6/core/src/openjdk/java/java/security/PrivilegedActionException.java classlib6/core/src/openjdk/java/java/security/PrivilegedExceptionAction.java classlib6/core/src/openjdk/java/java/security/ProtectionDomain.java classlib6/core/src/openjdk/java/java/security/Provider.java classlib6/core/src/openjdk/java/java/security/ProviderException.java classlib6/core/src/openjdk/java/java/security/PublicKey.java classlib6/core/src/openjdk/java/java/security/SecureClassLoader.java classlib6/core/src/openjdk/java/java/security/SecureRandom.java classlib6/core/src/openjdk/java/java/security/SecureRandomSpi.java classlib6/core/src/openjdk/java/java/security/Security.java classlib6/core/src/openjdk/java/java/security/SecurityPermission.java classlib6/core/src/openjdk/java/java/security/Signature.java classlib6/core/src/openjdk/java/java/security/SignatureException.java classlib6/core/src/openjdk/java/java/security/SignatureSpi.java classlib6/core/src/openjdk/java/java/security/SignedObject.java classlib6/core/src/openjdk/java/java/security/Signer.java classlib6/core/src/openjdk/java/java/security/Timestamp.java classlib6/core/src/openjdk/java/java/security/UnrecoverableEntryException.java classlib6/core/src/openjdk/java/java/security/UnrecoverableKeyException.java classlib6/core/src/openjdk/java/java/security/UnresolvedPermission.java classlib6/core/src/openjdk/java/java/security/UnresolvedPermissionCollection.java classlib6/core/src/openjdk/java/java/util/AbstractCollection.java classlib6/core/src/openjdk/java/java/util/AbstractList.java classlib6/core/src/openjdk/java/java/util/AbstractMap.java classlib6/core/src/openjdk/java/java/util/AbstractQueue.java classlib6/core/src/openjdk/java/java/util/AbstractSequentialList.java classlib6/core/src/openjdk/java/java/util/AbstractSet.java classlib6/core/src/openjdk/java/java/util/ArrayDeque.java classlib6/core/src/openjdk/java/java/util/ArrayList.java classlib6/core/src/openjdk/java/java/util/Arrays.java classlib6/core/src/openjdk/java/java/util/Calendar.java classlib6/core/src/openjdk/java/java/util/Collection.java classlib6/core/src/openjdk/java/java/util/Collections.java classlib6/core/src/openjdk/java/java/util/Comparator.java classlib6/core/src/openjdk/java/java/util/ConcurrentModificationException.java classlib6/core/src/openjdk/java/java/util/Currency.java classlib6/core/src/openjdk/java/java/util/Date.java classlib6/core/src/openjdk/java/java/util/Deque.java classlib6/core/src/openjdk/java/java/util/Dictionary.java classlib6/core/src/openjdk/java/java/util/DuplicateFormatFlagsException.java classlib6/core/src/openjdk/java/java/util/EmptyStackException.java classlib6/core/src/openjdk/java/java/util/EnumMap.java classlib6/core/src/openjdk/java/java/util/EnumSet.java classlib6/core/src/openjdk/java/java/util/Enumeration.java classlib6/core/src/openjdk/java/java/util/EventListener.java classlib6/core/src/openjdk/java/java/util/EventListenerProxy.java classlib6/core/src/openjdk/java/java/util/EventObject.java classlib6/core/src/openjdk/java/java/util/FormatFlagsConversionMismatchException.java classlib6/core/src/openjdk/java/java/util/Formattable.java classlib6/core/src/openjdk/java/java/util/FormattableFlags.java classlib6/core/src/openjdk/java/java/util/Formatter.java classlib6/core/src/openjdk/java/java/util/FormatterClosedException.java classlib6/core/src/openjdk/java/java/util/GregorianCalendar.java classlib6/core/src/openjdk/java/java/util/HashMap.java classlib6/core/src/openjdk/java/java/util/HashSet.java classlib6/core/src/openjdk/java/java/util/Hashtable.java classlib6/core/src/openjdk/java/java/util/IdentityHashMap.java classlib6/core/src/openjdk/java/java/util/IllegalFormatCodePointException.java classlib6/core/src/openjdk/java/java/util/IllegalFormatConversionException.java classlib6/core/src/openjdk/java/java/util/IllegalFormatException.java classlib6/core/src/openjdk/java/java/util/IllegalFormatFlagsException.java classlib6/core/src/openjdk/java/java/util/IllegalFormatPrecisionException.java classlib6/core/src/openjdk/java/java/util/IllegalFormatWidthException.java classlib6/core/src/openjdk/java/java/util/InputMismatchException.java classlib6/core/src/openjdk/java/java/util/InvalidPropertiesFormatException.java classlib6/core/src/openjdk/java/java/util/Iterator.java classlib6/core/src/openjdk/java/java/util/JumboEnumSet.java classlib6/core/src/openjdk/java/java/util/LinkedHashMap.java classlib6/core/src/openjdk/java/java/util/LinkedHashSet.java classlib6/core/src/openjdk/java/java/util/LinkedList.java classlib6/core/src/openjdk/java/java/util/List.java classlib6/core/src/openjdk/java/java/util/ListIterator.java classlib6/core/src/openjdk/java/java/util/ListResourceBundle.java classlib6/core/src/openjdk/java/java/util/Locale.java classlib6/core/src/openjdk/java/java/util/LocaleISOData.java classlib6/core/src/openjdk/java/java/util/Map.java classlib6/core/src/openjdk/java/java/util/MissingFormatArgumentException.java classlib6/core/src/openjdk/java/java/util/MissingFormatWidthException.java classlib6/core/src/openjdk/java/java/util/MissingResourceException.java classlib6/core/src/openjdk/java/java/util/NavigableMap.java classlib6/core/src/openjdk/java/java/util/NavigableSet.java classlib6/core/src/openjdk/java/java/util/NoSuchElementException.java classlib6/core/src/openjdk/java/java/util/Observable.java classlib6/core/src/openjdk/java/java/util/Observer.java classlib6/core/src/openjdk/java/java/util/PriorityQueue.java classlib6/core/src/openjdk/java/java/util/Properties.java classlib6/core/src/openjdk/java/java/util/PropertyPermission.java classlib6/core/src/openjdk/java/java/util/PropertyResourceBundle.java classlib6/core/src/openjdk/java/java/util/Queue.java classlib6/core/src/openjdk/java/java/util/RandomAccess.java classlib6/core/src/openjdk/java/java/util/RegularEnumSet.java classlib6/core/src/openjdk/java/java/util/ResourceBundle.java classlib6/core/src/openjdk/java/java/util/Scanner.java classlib6/core/src/openjdk/java/java/util/Set.java classlib6/core/src/openjdk/java/java/util/SimpleTimeZone.java classlib6/core/src/openjdk/java/java/util/SortedMap.java classlib6/core/src/openjdk/java/java/util/SortedSet.java classlib6/core/src/openjdk/java/java/util/Stack.java classlib6/core/src/openjdk/java/java/util/StringTokenizer.java classlib6/core/src/openjdk/java/java/util/TimeZone.java classlib6/core/src/openjdk/java/java/util/Timer.java classlib6/core/src/openjdk/java/java/util/TimerTask.java classlib6/core/src/openjdk/java/java/util/TooManyListenersException.java classlib6/core/src/openjdk/java/java/util/TreeMap.java classlib6/core/src/openjdk/java/java/util/TreeSet.java classlib6/core/src/openjdk/java/java/util/UUID.java classlib6/core/src/openjdk/java/java/util/UnknownFormatConversionException.java classlib6/core/src/openjdk/java/java/util/UnknownFormatFlagsException.java classlib6/core/src/openjdk/java/java/util/Vector.java classlib6/core/src/openjdk/java/java/util/WeakHashMap.java classlib6/core/src/openjdk/java/java/util/XMLUtils.java classlib6/core/src/openjdk/java/java/util/concurrent/ConcurrentSkipListMap.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/AbstractOwnableSynchronizer.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/Condition.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/Lock.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/LockSupport.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/ReadWriteLock.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/ReentrantLock.java classlib6/core/src/openjdk/java/java/util/concurrent/locks/ReentrantReadWriteLock.java classlib6/core/src/openjdk/java/java/util/logging/LogManager.java classlib6/core/src/openjdk/java/java/util/logging/Logger.java classlib6/core/src/openjdk/java/java/util/package.html Modified: classlib6/core/src/openjdk/java/java/awt/color/CMMException.java =================================================================== --- classlib6/core/src/openjdk/java/java/awt/color/CMMException.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/color/CMMException.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -3,9 +3,9 @@ * * 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. Sun designates this + * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. + * 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 @@ -17,9 +17,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * 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. */ /* Modified: classlib6/core/src/openjdk/java/java/awt/color/ColorSpace.java =================================================================== --- classlib6/core/src/openjdk/java/java/awt/color/ColorSpace.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/color/ColorSpace.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,12 +1,12 @@ /* - * Portions Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 1997, 2006, 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. Sun designates this + * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. + * 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 @@ -18,9 +18,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * 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. */ /********************************************************************** Modified: classlib6/core/src/openjdk/java/java/awt/color/ICC_ColorSpace.java =================================================================== --- classlib6/core/src/openjdk/java/java/awt/color/ICC_ColorSpace.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/color/ICC_ColorSpace.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,12 +1,12 @@ /* - * Portions Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 1997, 2007, 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. Sun designates this + * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. + * 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 @@ -18,9 +18,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * 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. */ /********************************************************************** Modified: classlib6/core/src/openjdk/java/java/awt/color/ICC_Profile.java =================================================================== --- classlib6/core/src/openjdk/java/java/awt/color/ICC_Profile.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/color/ICC_Profile.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,12 +1,12 @@ /* - * Portions Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 1997, 2006, 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. Sun designates this + * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. + * 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 @@ -18,9 +18,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * 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. */ /********************************************************************** @@ -945,14 +945,14 @@ */ public static ICC_Profile getInstance(String fileName) throws IOException { ICC_Profile thisProfile; - FileInputStream fis; + FileInputStream fis = null; - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkRead(fileName); + + File f = getProfileFile(fileName); + if (f != null) { + fis = new FileInputStream(f); } - - if ((fis = openProfile(fileName)) == null) { + if (fis == null) { throw new IOException("Cannot open file " + fileName); } @@ -1066,11 +1066,22 @@ void activateDeferredProfile() { byte profileData[]; FileInputStream fis; - String fileName = deferralInfo.filename; + final String fileName = deferralInfo.filename; profileActivator = null; deferralInfo = null; - if ((fis = openProfile(fileName)) == null) { + PrivilegedAction<FileInputStream> pa = new PrivilegedAction<FileInputStream>() { + public FileInputStream run() { + File f = getStandardProfileFile(fileName); + if (f != null) { + try { + return new FileInputStream(f); + } catch (FileNotFoundException e) {} + } + return null; + } + }; + if ((fis = AccessController.doPrivileged(pa)) == null) { throw new IllegalArgumentException("Cannot open file " + fileName); } try { @@ -1765,66 +1776,88 @@ * available, such as a profile for sRGB. Built-in profiles use .pf as * the file name extension for profiles, e.g. sRGB.pf. */ - private static FileInputStream openProfile(final String fileName) { - return (FileInputStream)java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - return privilegedOpenProfile(fileName); - } - }); - } - - /* - * this version is called from doPrivileged in privilegedOpenProfile. - * the whole method is privileged! - */ - private static FileInputStream privilegedOpenProfile(String fileName) { - FileInputStream fis = null; + private static File getProfileFile(String fileName) { String path, dir, fullPath; File f = new File(fileName); /* try absolute file name */ - + if (f.isAbsolute()) { + /* Rest of code has little sense for an absolute pathname, + so return here. */ + return f.isFile() ? f : null; + } if ((!f.isFile()) && ((path = System.getProperty("java.iccprofile.path")) != null)){ /* try relative to java.iccprofile.path */ StringTokenizer st = new StringTokenizer(path, File.pathSeparator); - while (st.hasMoreTokens() && (!f.isFile())) { + while (st.hasMoreTokens() && ((f == null) || (!f.isFile()))) { dir = st.nextToken(); fullPath = dir + File.separatorChar + fileName; f = new File(fullPath); + if (!isChildOf(f, dir)) { + f = null; } + } } - if ((!f.isFile()) && + if (((f == null) || (!f.isFile())) && ((path = System.getProperty("java.class.path")) != null)) { /* try relative to java.class.path */ StringTokenizer st = new StringTokenizer(path, File.pathSeparator); - while (st.hasMoreTokens() && (!f.isFile())) { + while (st.hasMoreTokens() && ((f == null) || (!f.isFile()))) { dir = st.nextToken(); fullPath = dir + File.separatorChar + fileName; f = new File(fullPath); + if (!isChildOf(f, dir)) { + f = null; } } + } + if ((f == null) || (!f.isFile())) { + /* try the directory of built-in profiles */ + f = getStandardProfileFile(fileName); + } + if (f != null && f.isFile()) { + return f; + } + return null; + } - if (!f.isFile()) { /* try the directory of built-in profiles */ - dir = System.getProperty("java.home") + + /** + * Returns a file object corresponding to a built-in profile + * specified by fileName. + * If there is no built-in profile with such name, then the method + * returns null. + */ + private static File getStandardProfileFile(String fileName) { + String dir = System.getProperty("java.home") + File.separatorChar + "lib" + File.separatorChar + "cmm"; - fullPath = dir + File.separatorChar + fileName; - f = new File(fullPath); + String fullPath = dir + File.separatorChar + fileName; + File f = new File(fullPath); + return (f.isFile() && isChildOf(f, dir)) ? f : null; } - if (f.isFile()) { + /** + * Checks whether given file resides inside give directory. + */ + private static boolean isChildOf(File f, String dirName) { try { - fis = new FileInputStream(f); - } catch (FileNotFoundException e) { + File dir = new File(dirName); + String canonicalDirName = dir.getCanonicalPath(); + if (!canonicalDirName.endsWith(File.separator)) { + canonicalDirName += File.separator; } + String canonicalFileName = f.getCanonicalPath(); + return canonicalFileName.startsWith(canonicalDirName); + } catch (IOException e) { + /* we do not expect the IOException here, because invocation + * of this function is always preceeded by isFile() call. + */ + return false; } - return fis; } - /* * Serialization support. * Modified: classlib6/core/src/openjdk/java/java/awt/color/ICC_ProfileGray.java =================================================================== --- classlib6/core/src/openjdk/java/java/awt/color/ICC_ProfileGray.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/color/ICC_ProfileGray.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,12 +1,12 @@ /* - * Portions Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 1997, 2007, 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. Sun designates this + * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. + * 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 @@ -18,9 +18,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * 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. */ /********************************************************************** Modified: classlib6/core/src/openjdk/java/java/awt/color/ICC_ProfileRGB.java =================================================================== --- classlib6/core/src/openjdk/java/java/awt/color/ICC_ProfileRGB.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/color/ICC_ProfileRGB.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,12 +1,12 @@ /* - * Portions Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 1997, 2007, 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. Sun designates this + * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. + * 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 @@ -18,9 +18,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * 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. */ /********************************************************************** Modified: classlib6/core/src/openjdk/java/java/awt/color/ProfileDataException.java =================================================================== --- classlib6/core/src/openjdk/java/java/awt/color/ProfileDataException.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/color/ProfileDataException.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,12 +1,12 @@ /* - * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 1997, 2000, 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. Sun designates this + * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. + * 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 @@ -18,9 +18,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ package java.awt.color; Modified: classlib6/core/src/openjdk/java/java/awt/color/package.html =================================================================== --- classlib6/core/src/openjdk/java/java/awt/color/package.html 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/color/package.html 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,12 +1,12 @@ <!-- - Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved. + Copyright (c) 1998, 1999, 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. Sun designates this + published by the Free Software Foundation. Oracle designates this particular file as subject to the "Classpath" exception as provided - by Sun in the LICENSE file that accompanied this code. + 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 @@ -18,9 +18,9 @@ 2 along with this work; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - CA 95054 USA or visit www.sun.com if you need additional information or - have any questions. + 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. --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> Modified: classlib6/core/src/openjdk/java/java/awt/image/IndexColorModel.java =================================================================== --- classlib6/core/src/openjdk/java/java/awt/image/IndexColorModel.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/awt/image/IndexColorModel.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2010, 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 @@ -129,6 +129,8 @@ private boolean allgrayopaque; private BigInteger validBits; + private sun.awt.image.BufImgSurfaceData.ICMColorData colorData = null; + private static int[] opaqueBits = {8, 8, 8}; private static int[] alphaBits = {8, 8, 8, 8}; @@ -1511,7 +1513,6 @@ * longer referenced. */ public void finalize() { - sun.awt.image.BufImgSurfaceData.freeNativeICMData(this); } /** Modified: classlib6/core/src/openjdk/java/java/beans/EventHandler.java =================================================================== --- classlib6/core/src/openjdk/java/java/beans/EventHandler.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/beans/EventHandler.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -32,7 +32,6 @@ import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.EventObject; import sun.reflect.misc.MethodUtil; /** @@ -279,9 +278,9 @@ public class EventHandler implements InvocationHandler { private Object target; private String action; - private String eventPropertyName; - private String listenerMethodName; - private AccessControlContext acc; + private final String eventPropertyName; + private final String listenerMethodName; + private final AccessControlContext acc = AccessController.getContext(); /** * Creates a new <code>EventHandler</code> object; @@ -309,7 +308,6 @@ * @see #getListenerMethodName */ public EventHandler(Object target, String action, String eventPropertyName, String listenerMethodName) { - this.acc = AccessController.getContext(); this.target = target; this.action = action; if (target == null) { @@ -421,7 +419,11 @@ * @see EventHandler */ public Object invoke(final Object proxy, final Method method, final Object[] arguments) { - return AccessController.doPrivileged(new PrivilegedAction() { + AccessControlContext acc = this.acc; + if ((acc == null) && (System.getSecurityManager() != null)) { + throw new SecurityException("AccessControlContext is not set"); + } + return AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { return invokeInternal(proxy, method, arguments); } @@ -481,7 +483,10 @@ throw new RuntimeException(ex); } catch (InvocationTargetException ex) { - throw new RuntimeException(ex.getTargetException()); + Throwable th = ex.getTargetException(); + throw (th instanceof RuntimeException) + ? (RuntimeException) th + : new RuntimeException(th); } } return null; Modified: classlib6/core/src/openjdk/java/java/beans/Introspector.java =================================================================== --- classlib6/core/src/openjdk/java/java/beans/Introspector.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/beans/Introspector.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -45,6 +45,7 @@ import java.util.List; import java.util.WeakHashMap; import java.util.TreeMap; +import sun.awt.AppContext; import sun.reflect.misc.ReflectUtil; /** @@ -111,9 +112,9 @@ // Static Caches to speed up introspection. private static Map declaredMethodCache = Collections.synchronizedMap(new WeakHashMap()); - private static Map beanInfoCache = - Collections.synchronizedMap(new WeakHashMap()); + private static final Object BEANINFO_CACHE = new Object(); + private Class beanClass; private BeanInfo explicitBeanInfo; private BeanInfo superBeanInfo; @@ -175,10 +176,18 @@ if (!ReflectUtil.isPackageAccessible(beanClass)) { return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); } - BeanInfo bi = (BeanInfo)beanInfoCache.get(beanClass); + Map<Class<?>, BeanInfo> map; + synchronized (BEANINFO_CACHE) { + map = (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE); + if (map == null) { + map = Collections.synchronizedMap(new WeakHashMap<Class<?>, BeanInfo>()); + AppContext.getAppContext().put(BEANINFO_CACHE, map); + } + } + BeanInfo bi = map.get(beanClass); if (bi == null) { bi = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); - beanInfoCache.put(beanClass, bi); + map.put(beanClass, bi); } return bi; } @@ -327,7 +336,10 @@ */ public static void flushCaches() { - beanInfoCache.clear(); + Map map = (Map) AppContext.getAppContext().get(BEANINFO_CACHE); + if (map != null) { + map.clear(); + } declaredMethodCache.clear(); } @@ -350,7 +362,10 @@ if (clz == null) { throw new NullPointerException(); } - beanInfoCache.remove(clz); + Map map = (Map) AppContext.getAppContext().get(BEANINFO_CACHE); + if (map != null) { + map.remove(clz); + } declaredMethodCache.remove(clz); } Modified: classlib6/core/src/openjdk/java/java/beans/MetaData.java =================================================================== --- classlib6/core/src/openjdk/java/java/beans/MetaData.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/beans/MetaData.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -331,31 +331,6 @@ return (oldC.size() == newC.size()) && oldC.containsAll(newC); } - static Object getPrivateField(final Object instance, final String name) { - return AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - Class type = instance.getClass(); - while ( true ) { - try { - Field field = type.getDeclaredField(name); - field.setAccessible(true); - return field.get( instance ); - } - catch (NoSuchFieldException exception) { - type = type.getSuperclass(); - if (type == null) { - throw new IllegalStateException("Could not find field " + name, exception); - } - } - catch (Exception exception) { - throw new IllegalStateException("Could not get value " + type.getName() + '.' + name, exception); - } - } - } - } ); - } - static final class EmptyList_PersistenceDelegate extends java_util_Collections { protected Expression instantiate(Object oldInstance, Encoder out) { return new Expression(oldInstance, Collections.class, "emptyList", null); @@ -496,7 +471,7 @@ static final class CheckedCollection_PersistenceDelegate extends java_util_Collections { protected Expression instantiate(Object oldInstance, Encoder out) { - Object type = getPrivateField(oldInstance, "type"); + Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type"); List list = new ArrayList((Collection) oldInstance); return new Expression(oldInstance, Collections.class, "checkedCollection", new Object[]{list, type}); } @@ -504,7 +479,7 @@ static final class CheckedList_PersistenceDelegate extends java_util_Collections { protected Expression instantiate(Object oldInstance, Encoder out) { - Object type = getPrivateField(oldInstance, "type"); + Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type"); List list = new LinkedList((Collection) oldInstance); return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type}); } @@ -512,7 +487,7 @@ static final class CheckedRandomAccessList_PersistenceDelegate extends java_util_Collections { protected Expression instantiate(Object oldInstance, Encoder out) { - Object type = getPrivateField(oldInstance, "type"); + Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type"); List list = new ArrayList((Collection) oldInstance); return new Expression(oldInstance, Collections.class, "checkedList", new Object[]{list, type}); } @@ -520,7 +495,7 @@ static final class CheckedSet_PersistenceDelegate extends java_util_Collections { protected Expression instantiate(Object oldInstance, Encoder out) { - Object type = getPrivateField(oldInstance, "type"); + Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type"); Set set = new HashSet((Set) oldInstance); return new Expression(oldInstance, Collections.class, "checkedSet", new Object[]{set, type}); } @@ -528,7 +503,7 @@ static final class CheckedSortedSet_PersistenceDelegate extends java_util_Collections { protected Expression instantiate(Object oldInstance, Encoder out) { - Object type = getPrivateField(oldInstance, "type"); + Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type"); SortedSet set = new TreeSet((SortedSet) oldInstance); return new Expression(oldInstance, Collections.class, "checkedSortedSet", new Object[]{set, type}); } @@ -536,8 +511,8 @@ static final class CheckedMap_PersistenceDelegate extends java_util_Collections { protected Expression instantiate(Object oldInstance, Encoder out) { - Object keyType = getPrivateField(oldInstance, "keyType"); - Object valueType = getPrivateField(oldInstance, "valueType"); + Object keyType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType"); + Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType"); Map map = new HashMap((Map) oldInstance); return new Expression(oldInstance, Collections.class, "checkedMap", new Object[]{map, keyType, valueType}); } @@ -545,8 +520,8 @@ static final class CheckedSortedMap_PersistenceDelegate extends java_util_Collections { protected Expression instantiate(Object oldInstance, Encoder out) { - Object keyType = getPrivateField(oldInstance, "keyType"); - Object valueType = getPrivateField(oldInstance, "valueType"); + Object keyType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType"); + Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType"); SortedMap map = new TreeMap((SortedMap) oldInstance); return new Expression(oldInstance, Collections.class, "checkedSortedMap", new Object[]{map, keyType, valueType}); } @@ -568,7 +543,7 @@ } private static Object getType(Object instance) { - return java_util_Collections.getPrivateField(instance, "keyType"); + return MetaData.getPrivateFieldValue(instance, "java.util.EnumMap.keyType"); } } @@ -587,7 +562,7 @@ } private static Object getType(Object instance) { - return java_util_Collections.getPrivateField(instance, "elementType"); + return MetaData.getPrivateFieldValue(instance, "java.util.EnumSet.elementType"); } } @@ -1268,7 +1243,7 @@ private Integer getAxis(Object object) { Box box = (Box) object; - return (Integer) java_util_Collections.getPrivateField(box.getLayout(), "axis"); + return (Integer) MetaData.getPrivateFieldValue(box.getLayout(), "javax.swing.BoxLayout.axis"); } } @@ -1351,6 +1326,7 @@ } class MetaData { + private static final Map<String,Field> fields = Collections.synchronizedMap(new WeakHashMap<String, Field>()); private static Hashtable internalPersistenceDelegates = new Hashtable(); private static Hashtable transientProperties = new Hashtable(); @@ -1706,4 +1682,35 @@ } tp.add(property); } + + static Object getPrivateFieldValue(Object instance, String name) { + Field field = fields.get(name); + if (field == null) { + int index = name.lastIndexOf('.'); + final String className = name.substring(0, index); + final String fieldName = name.substring(1 + index); + field = AccessController.doPrivileged(new PrivilegedAction<Field>() { + public Field run() { + try { + Field field = Class.forName(className).getDeclaredField(fieldName); + field.setAccessible(true); + return field; + } + catch (ClassNotFoundException exception) { + throw new IllegalStateException("Could not find class", exception); + } + catch (NoSuchFieldException exception) { + throw new IllegalStateException("Could not find field", exception); + } + } + }); + fields.put(name, field); + } + try { + return field.get(instance); + } + catch (IllegalAccessException exception) { + throw new IllegalStateException("Could not get value of the field", exception); + } + } } Modified: classlib6/core/src/openjdk/java/java/beans/Statement.java =================================================================== --- classlib6/core/src/openjdk/java/java/beans/Statement.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/beans/Statement.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -29,6 +29,10 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import com.sun.beans.finder.ClassFinder; import sun.reflect.misc.MethodUtil; @@ -61,9 +65,10 @@ } }; - Object target; - String methodName; - Object[] arguments; + private final AccessControlContext acc = AccessController.getContext(); + private final Object target; + private final String methodName; + private final Object[] arguments; /** * Creates a new <code>Statement</code> object with a <code>target</code>, @@ -141,6 +146,27 @@ } Object invoke() throws Exception { + AccessControlContext acc = this.acc; + if ((acc == null) && (System.getSecurityManager() != null)) { + throw new SecurityException("AccessControlContext is not set"); + } + try { + return AccessController.doPrivileged( + new PrivilegedExceptionAction<Object>() { + public Object run() + throws Exception { + return invokeInternal(); + } + }, + acc + ); + } + catch (PrivilegedActionException exception) { + throw exception.getException(); + } + } + + private Object invokeInternal() throws Exception { Object target = getTarget(); String methodName = getMethodName(); Modified: classlib6/core/src/openjdk/java/java/math/BigDecimal.java =================================================================== --- classlib6/core/src/openjdk/java/java/math/BigDecimal.java 2011-03-05 11:01:11 UTC (rev 5796) +++ classlib6/core/src/openjdk/java/java/math/BigDecimal.java 2011-03-05 11:09:31 UTC (rev 5797) @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, 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,9 @@ package java.math; +import java.util.Arrays; +import static java.math.BigInteger.LONG_MASK; + /** * Immutable, arbitrary-precision signed decimal numbers. A * {@code BigDecimal} consists of an arbitrary precision integer @@ -229,7 +232,7 @@ * @serial * @see #scale */ - private int scale = 0; // Note: this may have any value, so + private int scale; // Note: this may have any value, so // calculations must be done in longs /** * The number of decimal digits in this BigDecimal, or 0 if the @@ -240,25 +243,25 @@ * * @since 1.5 */ - private volatile transient int precision = 0; + private transient int precision; /** * Used to store the canonical string representation, if computed. */ - private volatile transient String stringCache = null; + private transient String stringCache; /** * Sentinel value for {@link #intCompact} indicating the * significand information is only available from {@code intVal}. */ - private static final long INFLATED = Long.MIN_VALUE; + static final long INFLATED = Long.MIN_VALUE; /** * If the absolute value of the significand of this BigDecimal is * less than or equal to {@code Long.MAX_VALUE}, the value can be * compactly stored in this field and used in computations. */ - private transient long intCompact = INFLATED; + private transient long intCompact; // All 18-digit base ten strings fit into a long; not all 19-digit // strings will @@ -269,21 +272,53 @@ /* Appease the serialization gods */ private static final long serialVersionUID = 6108874887143696463L; + private static final ThreadLocal<StringBuilderHelper> + threadLocalStringBuilderHelper = new ThreadLocal<StringBuilderHelper>() { + @Override + protected StringBuilderHelper initialValue() { + return new StringBuilderHelper(); + } + }; + // Cache of common small BigDecimal values. private static final BigDecimal zeroThroughTen[] = { - new BigDecimal(BigInteger.ZERO, 0, 0), - new BigDecimal(BigInteger.ONE, 1, 0), - new BigDecimal(BigInteger.valueOf(2), 2, 0), - new BigDecimal(BigInteger.valueOf(3), 3, 0), - new BigDecimal(BigInteger.valueOf(4), 4, 0), - new BigDecimal(BigInteger.valueOf(5), 5, 0), - new BigDecimal(BigInteger.valueOf(6), 6, 0), - new BigDecimal(BigInteger.valueOf(7), 7, 0), - new BigDecimal(BigInteger.valueOf(8), 8, 0), - new BigDecimal(BigInteger.valueOf(9), 9, 0), - new BigDecimal(BigInteger.TEN, 10, 0), + new BigDecimal(BigInteger.ZERO, 0, 0, 1), + new BigDecimal(BigInteger.ONE, 1, 0, 1), + new BigDecimal(BigInteger.valueOf(2), 2, 0, 1), + new BigDecimal(BigInteger.valueOf(3), 3, 0, 1), + new BigDecimal(BigInteger.valueOf(4), 4, 0, 1), + new BigDecimal(BigInteger.valueOf(5), 5, 0, 1), + new BigDecimal(BigInteger.valueOf(6), 6, 0, 1), + new BigDecimal(BigInteger.valueOf(7), 7, 0, 1), + new BigDecimal(BigInteger.valueOf(8), 8, 0, 1), + new BigDecimal(BigInteger.valueOf(9), 9, 0, 1), + new BigDecimal(BigInteger.TEN, 10, 0, 2), }; + // Cache of zero scaled by 0 - 15 + private static final BigDecimal[] ZERO_SCALED_BY = { + zeroThroughTen[0], + new BigDecimal(BigInteger.ZERO, 0, 1, 1), + new BigDecimal(BigInteger.ZERO, 0, 2, 1), + new BigDecimal(BigInteger.ZERO, 0, 3, 1), + new BigDecimal(BigInteger.ZERO, 0, 4, 1), + new BigDecimal(BigInteger.ZERO, 0, 5, 1), + new BigDecimal(BigInteger.ZERO, 0, 6, 1), + new BigDecimal(BigInteger.ZERO, 0, 7, 1), + new BigDecimal(BigInteger.ZERO, 0, 8, 1), + new BigDecimal(BigInteger.ZERO, 0, 9, 1), + new BigDecimal(BigInteger.ZERO, 0, 10, 1), + new BigDecimal(BigInteger.ZERO, 0, 11, 1), + new BigDecimal(BigInteger.ZERO, 0, 12, 1), + new BigDecimal(BigInteger.ZERO, 0, 13, 1), + new BigDecimal(BigInteger.ZERO, 0, 14, 1), + new BigDecimal(BigInteger.ZERO, 0, 15, 1), + }; + + // Half of Long.MIN_VALUE & Long.MAX_VALUE. + private static final long HALF_LONG_MAX_VALUE = Long.MAX_VALUE / 2; + private static final long HALF_LONG_MIN_VALUE = Long.MIN_VALUE / 2; + // Constants /** * The value 0, with a scale of 0. @@ -312,6 +347,18 @@ // Constructors /** + * Trusted package private constructor. + * Trusted simply means if val is INFLATED, intVal could not be null and + * if intVal is null, val could not be INFLATED. + */ + BigDecimal(BigInteger intVal, long val, int scale, int prec) { + this.scale = scale; + this.precision = prec; + this.intCompact = val; + this.intVal = intVal; + } + + /** * Translates a character array representation of a * {@code BigDecimal} into a {@code BigDecimal}, accepting the * same sequence of characters as the {@link #BigDecimal(String)} @@ -331,11 +378,20 @@ * @since 1.5 */ public BigDecimal(char[] in, int offset, int len) { + // protect against huge length. + if (offset+len > in.length || offset < 0) + throw new NumberFormatException(); // This is the primary string to BigDecimal constructor; all // incoming strings end up here; it uses explicit (inline) // parsing for speed and generates at most one intermediate - // (temporary) object (a char[] array). + // (temporary) object (a char[] array) for non-compact case. + // Use locals for all fields values until completion + int prec = 0; // record precision value + int scl = 0; // record scale value + long rs = 0; // the compact value in long + BigInteger rb = null; // the inflated value in BigInteger + // use array bounds checking to handle too-long, len == 0, // bad offset, etc. try { @@ -351,27 +407,62 @@ } // should now be at numeric part of the significand - int dotoff = -1; // '.' offset, -1 if none + boolean dot = false; // true when there is a '.' int cfirst = offset; // record start of integer long exp = 0; // exponent - if (len > in.length) // protect against huge length - throw new NumberFormatException(); - char coeff[] = new char[len]; // integer significand array - char c; // work + char c; // current character + boolean isCompact = (len <= MAX_COMPACT_DIGITS); + // integer significand array & idx is the index to it. The array + // is ONLY used when we can't use a compact representation. + char coeff[] = isCompact ? null : new char[len]; + int idx = 0; + for (; len > 0; offset++, len--) { c = in[offset]; + // have digit if ((c >= '0' && c <= '9') || Character.isDigit(c)) { - // have digit - coeff[precision] = c; - precision++; // count of digits + // First compact case, we need not to preserve the character + // and we can just compute the value in place. + if (isCompact) { + int digit = Character.digit(c, 10); + if (digit == 0) { + if (prec == 0) + prec = 1; + else if (rs != 0) { + rs *= 10; + ++prec; + } // else digit is a redundant leading zero + } else { + if (prec != 1 || rs != 0) + ++prec; // prec unchanged if preceded by 0s + rs = rs * 10 + digit; + } + } else { // the unscaled value is likely a BigInteger object. + if (c == '0' || Character.digit(c, 10) == 0) { + if (prec == 0) { + coeff[idx] = c; + prec = 1; + } else if (idx != 0) { + coeff[idx++] = c; + ++prec; + } // else c must be a redundant leading zero + } else { + if (prec != 1 || idx != 0) + ++prec; // prec unchanged if preceded by 0s + coeff[idx++] = c; + } + } + if (dot) + ++scl; continue; } + // have dot if (c == '.') { // have dot - if (dotoff >= 0) // two dots + if (dot) // two dots throw new NumberFormatException(); -... [truncated message content] |