1.1 --- a/rt/emul/compact/src/main/java/java/io/BufferedInputStream.java Thu Oct 03 15:51:55 2013 +0200
1.2 +++ b/rt/emul/compact/src/main/java/java/io/BufferedInputStream.java Thu Oct 03 17:36:44 2013 +0200
1.3 @@ -24,7 +24,6 @@
1.4 */
1.5
1.6 package java.io;
1.7 -import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
1.8
1.9 /**
1.10 * A <code>BufferedInputStream</code> adds
1.11 @@ -59,16 +58,6 @@
1.12 */
1.13 protected volatile byte buf[];
1.14
1.15 - /**
1.16 - * Atomic updater to provide compareAndSet for buf. This is
1.17 - * necessary because closes can be asynchronous. We use nullness
1.18 - * of buf[] as primary indicator that this stream is closed. (The
1.19 - * "in" field is also nulled out on close.)
1.20 - */
1.21 - private static final
1.22 - AtomicReferenceFieldUpdater<BufferedInputStream, byte[]> bufUpdater =
1.23 - AtomicReferenceFieldUpdater.newUpdater
1.24 - (BufferedInputStream.class, byte[].class, "buf");
1.25
1.26 /**
1.27 * The index one greater than the index of the last valid byte in
1.28 @@ -221,14 +210,6 @@
1.29 nsz = marklimit;
1.30 byte nbuf[] = new byte[nsz];
1.31 System.arraycopy(buffer, 0, nbuf, 0, pos);
1.32 - if (!bufUpdater.compareAndSet(this, buffer, nbuf)) {
1.33 - // Can't replace buf if there was an async close.
1.34 - // Note: This would need to be changed if fill()
1.35 - // is ever made accessible to multiple threads.
1.36 - // But for now, the only way CAS can fail is via close.
1.37 - // assert buf == null;
1.38 - throw new IOException("Stream closed");
1.39 - }
1.40 buffer = nbuf;
1.41 }
1.42 count = pos;
1.43 @@ -465,13 +446,12 @@
1.44 public void close() throws IOException {
1.45 byte[] buffer;
1.46 while ( (buffer = buf) != null) {
1.47 - if (bufUpdater.compareAndSet(this, buffer, null)) {
1.48 - InputStream input = in;
1.49 - in = null;
1.50 - if (input != null)
1.51 - input.close();
1.52 - return;
1.53 - }
1.54 + InputStream input = in;
1.55 + buf = null;
1.56 + in = null;
1.57 + if (input != null)
1.58 + input.close();
1.59 + return;
1.60 // Else retry in case a new buf was CASed in fill()
1.61 }
1.62 }
2.1 --- a/rt/emul/compact/src/main/java/java/io/FileDescriptor.java Thu Oct 03 15:51:55 2013 +0200
2.2 +++ b/rt/emul/compact/src/main/java/java/io/FileDescriptor.java Thu Oct 03 17:36:44 2013 +0200
2.3 @@ -134,36 +134,6 @@
2.4 */
2.5 public native void sync() throws SyncFailedException;
2.6
2.7 - /* This routine initializes JNI field offsets for the class */
2.8 - private static native void initIDs();
2.9 -
2.10 - static {
2.11 - initIDs();
2.12 - }
2.13 -
2.14 - // Set up JavaIOFileDescriptorAccess in SharedSecrets
2.15 - static {
2.16 - sun.misc.SharedSecrets.setJavaIOFileDescriptorAccess(
2.17 - new sun.misc.JavaIOFileDescriptorAccess() {
2.18 - public void set(FileDescriptor obj, int fd) {
2.19 - obj.fd = fd;
2.20 - }
2.21 -
2.22 - public int get(FileDescriptor obj) {
2.23 - return obj.fd;
2.24 - }
2.25 -
2.26 - public void setHandle(FileDescriptor obj, long handle) {
2.27 - throw new UnsupportedOperationException();
2.28 - }
2.29 -
2.30 - public long getHandle(FileDescriptor obj) {
2.31 - throw new UnsupportedOperationException();
2.32 - }
2.33 - }
2.34 - );
2.35 - }
2.36 -
2.37 // package private methods used by FIS, FOS and RAF
2.38
2.39 int incrementAndGetUseCount() {
3.1 --- a/rt/emul/compact/src/main/java/java/io/FileInputStream.java Thu Oct 03 15:51:55 2013 +0200
3.2 +++ b/rt/emul/compact/src/main/java/java/io/FileInputStream.java Thu Oct 03 17:36:44 2013 +0200
3.3 @@ -25,8 +25,6 @@
3.4
3.5 package java.io;
3.6
3.7 -import java.nio.channels.FileChannel;
3.8 -import sun.nio.ch.FileChannelImpl;
3.9
3.10
3.11 /**
3.12 @@ -51,7 +49,7 @@
3.13 /* File Descriptor - handle to the open file */
3.14 private final FileDescriptor fd;
3.15
3.16 - private FileChannel channel = null;
3.17 +// private FileChannel channel = null;
3.18
3.19 private final Object closeLock = new Object();
3.20 private volatile boolean closed = false;
3.21 @@ -125,17 +123,7 @@
3.22 * @see java.lang.SecurityManager#checkRead(java.lang.String)
3.23 */
3.24 public FileInputStream(File file) throws FileNotFoundException {
3.25 - String name = (file != null ? file.getPath() : null);
3.26 - SecurityManager security = System.getSecurityManager();
3.27 - if (security != null) {
3.28 - security.checkRead(name);
3.29 - }
3.30 - if (name == null) {
3.31 - throw new NullPointerException();
3.32 - }
3.33 - fd = new FileDescriptor();
3.34 - fd.incrementAndGetUseCount();
3.35 - open(name);
3.36 + throw new SecurityException();
3.37 }
3.38
3.39 /**
3.40 @@ -163,21 +151,7 @@
3.41 * @see SecurityManager#checkRead(java.io.FileDescriptor)
3.42 */
3.43 public FileInputStream(FileDescriptor fdObj) {
3.44 - SecurityManager security = System.getSecurityManager();
3.45 - if (fdObj == null) {
3.46 - throw new NullPointerException();
3.47 - }
3.48 - if (security != null) {
3.49 - security.checkRead(fdObj);
3.50 - }
3.51 - fd = fdObj;
3.52 -
3.53 - /*
3.54 - * FileDescriptor is being shared by streams.
3.55 - * Ensure that it's GC'ed only when all the streams/channels are done
3.56 - * using it.
3.57 - */
3.58 - fd.incrementAndGetUseCount();
3.59 + throw new SecurityException();
3.60 }
3.61
3.62 /**
3.63 @@ -303,15 +277,15 @@
3.64 }
3.65 closed = true;
3.66 }
3.67 - if (channel != null) {
3.68 - /*
3.69 - * Decrement the FD use count associated with the channel
3.70 - * The use count is incremented whenever a new channel
3.71 - * is obtained from this stream.
3.72 - */
3.73 - fd.decrementAndGetUseCount();
3.74 - channel.close();
3.75 - }
3.76 +// if (channel != null) {
3.77 +// /*
3.78 +// * Decrement the FD use count associated with the channel
3.79 +// * The use count is incremented whenever a new channel
3.80 +// * is obtained from this stream.
3.81 +// */
3.82 +// fd.decrementAndGetUseCount();
3.83 +// channel.close();
3.84 +// }
3.85
3.86 /*
3.87 * Decrement the FD use count associated with this stream
3.88 @@ -358,21 +332,21 @@
3.89 * @since 1.4
3.90 * @spec JSR-51
3.91 */
3.92 - public FileChannel getChannel() {
3.93 - synchronized (this) {
3.94 - if (channel == null) {
3.95 - channel = FileChannelImpl.open(fd, true, false, this);
3.96 -
3.97 - /*
3.98 - * Increment fd's use count. Invoking the channel's close()
3.99 - * method will result in decrementing the use count set for
3.100 - * the channel.
3.101 - */
3.102 - fd.incrementAndGetUseCount();
3.103 - }
3.104 - return channel;
3.105 - }
3.106 - }
3.107 +// public FileChannel getChannel() {
3.108 +// synchronized (this) {
3.109 +// if (channel == null) {
3.110 +// channel = FileChannelImpl.open(fd, true, false, this);
3.111 +//
3.112 +// /*
3.113 +// * Increment fd's use count. Invoking the channel's close()
3.114 +// * method will result in decrementing the use count set for
3.115 +// * the channel.
3.116 +// */
3.117 +// fd.incrementAndGetUseCount();
3.118 +// }
3.119 +// return channel;
3.120 +// }
3.121 +// }
3.122
3.123 private static native void initIDs();
3.124
4.1 --- a/rt/emul/compact/src/main/java/java/io/FileOutputStream.java Thu Oct 03 15:51:55 2013 +0200
4.2 +++ b/rt/emul/compact/src/main/java/java/io/FileOutputStream.java Thu Oct 03 17:36:44 2013 +0200
4.3 @@ -25,8 +25,6 @@
4.4
4.5 package java.io;
4.6
4.7 -import java.nio.channels.FileChannel;
4.8 -import sun.nio.ch.FileChannelImpl;
4.9
4.10
4.11 /**
4.12 @@ -65,7 +63,7 @@
4.13 /**
4.14 * The associated channel, initalized lazily.
4.15 */
4.16 - private FileChannel channel;
4.17 +// private FileChannel channel;
4.18
4.19 private final Object closeLock = new Object();
4.20 private volatile boolean closed = false;
4.21 @@ -197,19 +195,7 @@
4.22 public FileOutputStream(File file, boolean append)
4.23 throws FileNotFoundException
4.24 {
4.25 - String name = (file != null ? file.getPath() : null);
4.26 - SecurityManager security = System.getSecurityManager();
4.27 - if (security != null) {
4.28 - security.checkWrite(name);
4.29 - }
4.30 - if (name == null) {
4.31 - throw new NullPointerException();
4.32 - }
4.33 - this.fd = new FileDescriptor();
4.34 - this.append = append;
4.35 -
4.36 - fd.incrementAndGetUseCount();
4.37 - open(name, append);
4.38 + throw new SecurityException();
4.39 }
4.40
4.41 /**
4.42 @@ -236,22 +222,7 @@
4.43 * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor)
4.44 */
4.45 public FileOutputStream(FileDescriptor fdObj) {
4.46 - SecurityManager security = System.getSecurityManager();
4.47 - if (fdObj == null) {
4.48 - throw new NullPointerException();
4.49 - }
4.50 - if (security != null) {
4.51 - security.checkWrite(fdObj);
4.52 - }
4.53 - this.fd = fdObj;
4.54 - this.append = false;
4.55 -
4.56 - /*
4.57 - * FileDescriptor is being shared by streams.
4.58 - * Ensure that it's GC'ed only when all the streams/channels are done
4.59 - * using it.
4.60 - */
4.61 - fd.incrementAndGetUseCount();
4.62 + throw new SecurityException();
4.63 }
4.64
4.65 /**
4.66 @@ -338,16 +309,16 @@
4.67 }
4.68 closed = true;
4.69 }
4.70 -
4.71 - if (channel != null) {
4.72 - /*
4.73 - * Decrement FD use count associated with the channel
4.74 - * The use count is incremented whenever a new channel
4.75 - * is obtained from this stream.
4.76 - */
4.77 - fd.decrementAndGetUseCount();
4.78 - channel.close();
4.79 - }
4.80 +//
4.81 +// if (channel != null) {
4.82 +// /*
4.83 +// * Decrement FD use count associated with the channel
4.84 +// * The use count is incremented whenever a new channel
4.85 +// * is obtained from this stream.
4.86 +// */
4.87 +// fd.decrementAndGetUseCount();
4.88 +// channel.close();
4.89 +// }
4.90
4.91 /*
4.92 * Decrement FD use count associated with this stream
4.93 @@ -395,21 +366,21 @@
4.94 * @since 1.4
4.95 * @spec JSR-51
4.96 */
4.97 - public FileChannel getChannel() {
4.98 - synchronized (this) {
4.99 - if (channel == null) {
4.100 - channel = FileChannelImpl.open(fd, false, true, append, this);
4.101 -
4.102 - /*
4.103 - * Increment fd's use count. Invoking the channel's close()
4.104 - * method will result in decrementing the use count set for
4.105 - * the channel.
4.106 - */
4.107 - fd.incrementAndGetUseCount();
4.108 - }
4.109 - return channel;
4.110 - }
4.111 - }
4.112 +// public FileChannel getChannel() {
4.113 +// synchronized (this) {
4.114 +// if (channel == null) {
4.115 +// channel = FileChannelImpl.open(fd, false, true, append, this);
4.116 +//
4.117 +// /*
4.118 +// * Increment fd's use count. Invoking the channel's close()
4.119 +// * method will result in decrementing the use count set for
4.120 +// * the channel.
4.121 +// */
4.122 +// fd.incrementAndGetUseCount();
4.123 +// }
4.124 +// return channel;
4.125 +// }
4.126 +// }
4.127
4.128 /**
4.129 * Cleans up the connection to the file, and ensures that the
5.1 --- a/rt/emul/compact/src/main/java/java/nio/charset/CharsetDecoder.java Thu Oct 03 15:51:55 2013 +0200
5.2 +++ b/rt/emul/compact/src/main/java/java/nio/charset/CharsetDecoder.java Thu Oct 03 17:36:44 2013 +0200
5.3 @@ -1,26 +1,26 @@
5.4 /*
5.5 - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
5.6 - * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
5.7 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
5.8 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.9 *
5.10 + * This code is free software; you can redistribute it and/or modify it
5.11 + * under the terms of the GNU General Public License version 2 only, as
5.12 + * published by the Free Software Foundation. Oracle designates this
5.13 + * particular file as subject to the "Classpath" exception as provided
5.14 + * by Oracle in the LICENSE file that accompanied this code.
5.15 *
5.16 + * This code is distributed in the hope that it will be useful, but WITHOUT
5.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5.18 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5.19 + * version 2 for more details (a copy is included in the LICENSE file that
5.20 + * accompanied this code).
5.21 *
5.22 + * You should have received a copy of the GNU General Public License version
5.23 + * 2 along with this work; if not, write to the Free Software Foundation,
5.24 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5.25 *
5.26 - *
5.27 - *
5.28 - *
5.29 - *
5.30 - *
5.31 - *
5.32 - *
5.33 - *
5.34 - *
5.35 - *
5.36 - *
5.37 - *
5.38 - *
5.39 - *
5.40 - *
5.41 - *
5.42 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5.43 + * or visit www.oracle.com if you need additional information or have any
5.44 + * questions.
5.45 */
5.46
5.47 // -- This file was mechanically generated: Do not edit! -- //
6.1 --- a/rt/emul/compact/src/main/java/java/nio/charset/CharsetEncoder.java Thu Oct 03 15:51:55 2013 +0200
6.2 +++ b/rt/emul/compact/src/main/java/java/nio/charset/CharsetEncoder.java Thu Oct 03 17:36:44 2013 +0200
6.3 @@ -1,26 +1,26 @@
6.4 /*
6.5 - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
6.6 - * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6.7 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
6.8 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.9 *
6.10 + * This code is free software; you can redistribute it and/or modify it
6.11 + * under the terms of the GNU General Public License version 2 only, as
6.12 + * published by the Free Software Foundation. Oracle designates this
6.13 + * particular file as subject to the "Classpath" exception as provided
6.14 + * by Oracle in the LICENSE file that accompanied this code.
6.15 *
6.16 + * This code is distributed in the hope that it will be useful, but WITHOUT
6.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.18 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.19 + * version 2 for more details (a copy is included in the LICENSE file that
6.20 + * accompanied this code).
6.21 *
6.22 + * You should have received a copy of the GNU General Public License version
6.23 + * 2 along with this work; if not, write to the Free Software Foundation,
6.24 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.25 *
6.26 - *
6.27 - *
6.28 - *
6.29 - *
6.30 - *
6.31 - *
6.32 - *
6.33 - *
6.34 - *
6.35 - *
6.36 - *
6.37 - *
6.38 - *
6.39 - *
6.40 - *
6.41 - *
6.42 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6.43 + * or visit www.oracle.com if you need additional information or have any
6.44 + * questions.
6.45 */
6.46
6.47 // -- This file was mechanically generated: Do not edit! -- //
7.1 --- a/rt/emul/compact/src/main/java/java/util/Locale.java Thu Oct 03 15:51:55 2013 +0200
7.2 +++ b/rt/emul/compact/src/main/java/java/util/Locale.java Thu Oct 03 17:36:44 2013 +0200
7.3 @@ -514,6 +514,15 @@
7.4 private static final int DISPLAY_COUNTRY = 1;
7.5 private static final int DISPLAY_VARIANT = 2;
7.6 private static final int DISPLAY_SCRIPT = 3;
7.7 +
7.8 + static Locale getInstance(String language, String script, String region, String v, Object object) {
7.9 + return new Locale(language, script, region);
7.10 + }
7.11 +
7.12 + static Locale getInstance(String no, String no0, String ny) {
7.13 + return new Locale(no, no0, ny);
7.14 + }
7.15 +
7.16 private String language;
7.17 private String country;
7.18 private String variant;
7.19 @@ -629,6 +638,26 @@
7.20 }
7.21
7.22 /**
7.23 + * Gets the current value of the default locale for the specified Category
7.24 + * for this instance of the Java Virtual Machine.
7.25 + * <p>
7.26 + * The Java Virtual Machine sets the default locale during startup based
7.27 + * on the host environment. It is used by many locale-sensitive methods
7.28 + * if no locale is explicitly specified. It can be changed using the
7.29 + * setDefault(Locale.Category, Locale) method.
7.30 + *
7.31 + * @param category - the specified category to get the default locale
7.32 + * @throws NullPointerException - if category is null
7.33 + * @return the default locale for the specified Category for this instance
7.34 + * of the Java Virtual Machine
7.35 + * @see #setDefault(Locale.Category, Locale)
7.36 + * @since 1.7
7.37 + */
7.38 + public static Locale getDefault(Locale.Category category) {
7.39 + return Locale.US;
7.40 + }
7.41 +
7.42 + /**
7.43 * Sets the default locale for this instance of the Java Virtual Machine.
7.44 * This does not affect the host locale.
7.45 * <p>
7.46 @@ -938,5 +967,46 @@
7.47 return true;
7.48 }
7.49
7.50 + /**
7.51 + * Enum for locale categories. These locale categories are used to get/set
7.52 + * the default locale for the specific functionality represented by the
7.53 + * category.
7.54 + *
7.55 + * @see #getDefault(Locale.Category)
7.56 + * @see #setDefault(Locale.Category, Locale)
7.57 + * @since 1.7
7.58 + */
7.59 + public enum Category {
7.60 +
7.61 + /**
7.62 + * Category used to represent the default locale for
7.63 + * displaying user interfaces.
7.64 + */
7.65 + DISPLAY("user.language.display",
7.66 + "user.script.display",
7.67 + "user.country.display",
7.68 + "user.variant.display"),
7.69 +
7.70 + /**
7.71 + * Category used to represent the default locale for
7.72 + * formatting dates, numbers, and/or currencies.
7.73 + */
7.74 + FORMAT("user.language.format",
7.75 + "user.script.format",
7.76 + "user.country.format",
7.77 + "user.variant.format");
7.78 +
7.79 + Category(String languageKey, String scriptKey, String countryKey, String variantKey) {
7.80 + this.languageKey = languageKey;
7.81 + this.scriptKey = scriptKey;
7.82 + this.countryKey = countryKey;
7.83 + this.variantKey = variantKey;
7.84 + }
7.85 +
7.86 + final String languageKey;
7.87 + final String scriptKey;
7.88 + final String countryKey;
7.89 + final String variantKey;
7.90 + }
7.91
7.92 }
8.1 --- a/rt/emul/compact/src/main/java/java/util/Properties.java Thu Oct 03 15:51:55 2013 +0200
8.2 +++ b/rt/emul/compact/src/main/java/java/util/Properties.java Thu Oct 03 17:36:44 2013 +0200
8.3 @@ -861,12 +861,11 @@
8.4 * @since 1.5
8.5 */
8.6 public synchronized void loadFromXML(InputStream in)
8.7 - throws IOException, InvalidPropertiesFormatException
8.8 + throws IOException
8.9 {
8.10 if (in == null)
8.11 throw new NullPointerException();
8.12 - XMLUtils.load(this, in);
8.13 - in.close();
8.14 + throw new IOException();
8.15 }
8.16
8.17 /**
8.18 @@ -933,7 +932,7 @@
8.19 {
8.20 if (os == null)
8.21 throw new NullPointerException();
8.22 - XMLUtils.save(this, os, comment, encoding);
8.23 + throw new IOException();
8.24 }
8.25
8.26 /**
9.1 --- a/rt/emul/compact/src/main/java/java/util/PropertyResourceBundle.java Thu Oct 03 15:51:55 2013 +0200
9.2 +++ b/rt/emul/compact/src/main/java/java/util/PropertyResourceBundle.java Thu Oct 03 17:36:44 2013 +0200
9.3 @@ -42,7 +42,6 @@
9.4 import java.io.InputStream;
9.5 import java.io.Reader;
9.6 import java.io.IOException;
9.7 -import sun.util.ResourceBundleEnumeration;
9.8
9.9 /**
9.10 * <code>PropertyResourceBundle</code> is a concrete subclass of
9.11 @@ -187,4 +186,57 @@
9.12 // ==================privates====================
9.13
9.14 private Map<String,Object> lookup;
9.15 +
9.16 +
9.17 + /**
9.18 + * Implements an Enumeration that combines elements from a Set and
9.19 + * an Enumeration. Used by ListResourceBundle and PropertyResourceBundle.
9.20 + */
9.21 + static class ResourceBundleEnumeration implements Enumeration<String> {
9.22 +
9.23 + Set<String> set;
9.24 + Iterator<String> iterator;
9.25 + Enumeration<String> enumeration; // may remain null
9.26 +
9.27 + /**
9.28 + * Constructs a resource bundle enumeration.
9.29 + * @param set an set providing some elements of the enumeration
9.30 + * @param enumeration an enumeration providing more elements of the enumeration.
9.31 + * enumeration may be null.
9.32 + */
9.33 + public ResourceBundleEnumeration(Set<String> set, Enumeration<String> enumeration) {
9.34 + this.set = set;
9.35 + this.iterator = set.iterator();
9.36 + this.enumeration = enumeration;
9.37 + }
9.38 +
9.39 + String next = null;
9.40 +
9.41 + public boolean hasMoreElements() {
9.42 + if (next == null) {
9.43 + if (iterator.hasNext()) {
9.44 + next = iterator.next();
9.45 + } else if (enumeration != null) {
9.46 + while (next == null && enumeration.hasMoreElements()) {
9.47 + next = enumeration.nextElement();
9.48 + if (set.contains(next)) {
9.49 + next = null;
9.50 + }
9.51 + }
9.52 + }
9.53 + }
9.54 + return next != null;
9.55 + }
9.56 +
9.57 + public String nextElement() {
9.58 + if (hasMoreElements()) {
9.59 + String result = next;
9.60 + next = null;
9.61 + return result;
9.62 + } else {
9.63 + throw new NoSuchElementException();
9.64 + }
9.65 + }
9.66 + }
9.67 +
9.68 }
10.1 --- a/rt/emul/compact/src/main/java/java/util/ResourceBundle.java Thu Oct 03 15:51:55 2013 +0200
10.2 +++ b/rt/emul/compact/src/main/java/java/util/ResourceBundle.java Thu Oct 03 17:36:44 2013 +0200
10.3 @@ -45,19 +45,7 @@
10.4 import java.lang.ref.ReferenceQueue;
10.5 import java.lang.ref.SoftReference;
10.6 import java.lang.ref.WeakReference;
10.7 -import java.net.JarURLConnection;
10.8 import java.net.URL;
10.9 -import java.net.URLConnection;
10.10 -import java.security.AccessController;
10.11 -import java.security.PrivilegedAction;
10.12 -import java.security.PrivilegedActionException;
10.13 -import java.security.PrivilegedExceptionAction;
10.14 -import java.util.concurrent.ConcurrentHashMap;
10.15 -import java.util.concurrent.ConcurrentMap;
10.16 -import java.util.jar.JarEntry;
10.17 -
10.18 -import sun.util.locale.BaseLocale;
10.19 -import sun.util.locale.LocaleObjectCache;
10.20
10.21
10.22 /**
10.23 @@ -288,8 +276,8 @@
10.24 * This variable would be better named "cache", but we keep the old
10.25 * name for compatibility with some workarounds for bug 4212439.
10.26 */
10.27 - private static final ConcurrentMap<CacheKey, BundleReference> cacheList
10.28 - = new ConcurrentHashMap<>(INITIAL_CACHE_SIZE);
10.29 + private static final Map<CacheKey, BundleReference> cacheList
10.30 + = new HashMap<>(INITIAL_CACHE_SIZE);
10.31
10.32 /**
10.33 * Queue for reference objects referring to class loaders or bundles.
10.34 @@ -410,65 +398,6 @@
10.35 return locale;
10.36 }
10.37
10.38 - /*
10.39 - * Automatic determination of the ClassLoader to be used to load
10.40 - * resources on behalf of the client. N.B. The client is getLoader's
10.41 - * caller's caller.
10.42 - */
10.43 - private static ClassLoader getLoader() {
10.44 - Class[] stack = getClassContext();
10.45 - /* Magic number 2 identifies our caller's caller */
10.46 - Class c = stack[2];
10.47 - ClassLoader cl = (c == null) ? null : c.getClassLoader();
10.48 - if (cl == null) {
10.49 - // When the caller's loader is the boot class loader, cl is null
10.50 - // here. In that case, ClassLoader.getSystemClassLoader() may
10.51 - // return the same class loader that the application is
10.52 - // using. We therefore use a wrapper ClassLoader to create a
10.53 - // separate scope for bundles loaded on behalf of the Java
10.54 - // runtime so that these bundles cannot be returned from the
10.55 - // cache to the application (5048280).
10.56 - cl = RBClassLoader.INSTANCE;
10.57 - }
10.58 - return cl;
10.59 - }
10.60 -
10.61 - private static native Class[] getClassContext();
10.62 -
10.63 - /**
10.64 - * A wrapper of ClassLoader.getSystemClassLoader().
10.65 - */
10.66 - private static class RBClassLoader extends ClassLoader {
10.67 - private static final RBClassLoader INSTANCE = AccessController.doPrivileged(
10.68 - new PrivilegedAction<RBClassLoader>() {
10.69 - public RBClassLoader run() {
10.70 - return new RBClassLoader();
10.71 - }
10.72 - });
10.73 - private static final ClassLoader loader = ClassLoader.getSystemClassLoader();
10.74 -
10.75 - private RBClassLoader() {
10.76 - }
10.77 - public Class<?> loadClass(String name) throws ClassNotFoundException {
10.78 - if (loader != null) {
10.79 - return loader.loadClass(name);
10.80 - }
10.81 - return Class.forName(name);
10.82 - }
10.83 - public URL getResource(String name) {
10.84 - if (loader != null) {
10.85 - return loader.getResource(name);
10.86 - }
10.87 - return ClassLoader.getSystemResource(name);
10.88 - }
10.89 - public InputStream getResourceAsStream(String name) {
10.90 - if (loader != null) {
10.91 - return loader.getResourceAsStream(name);
10.92 - }
10.93 - return ClassLoader.getSystemResourceAsStream(name);
10.94 - }
10.95 - }
10.96 -
10.97 /**
10.98 * Sets the parent bundle of this bundle.
10.99 * The parent bundle is searched by {@link #getObject getObject}
10.100 @@ -492,7 +421,6 @@
10.101 // These three are the actual keys for lookup in Map.
10.102 private String name;
10.103 private Locale locale;
10.104 - private LoaderReference loaderRef;
10.105
10.106 // bundle format which is necessary for calling
10.107 // Control.needsReload().
10.108 @@ -515,14 +443,9 @@
10.109 // of this instance.
10.110 private int hashCodeCache;
10.111
10.112 - CacheKey(String baseName, Locale locale, ClassLoader loader) {
10.113 + CacheKey(String baseName, Locale locale) {
10.114 this.name = baseName;
10.115 this.locale = locale;
10.116 - if (loader == null) {
10.117 - this.loaderRef = null;
10.118 - } else {
10.119 - loaderRef = new LoaderReference(loader, referenceQueue, this);
10.120 - }
10.121 calculateHashCode();
10.122 }
10.123
10.124 @@ -550,10 +473,6 @@
10.125 return this;
10.126 }
10.127
10.128 - ClassLoader getLoader() {
10.129 - return (loaderRef != null) ? loaderRef.get() : null;
10.130 - }
10.131 -
10.132 public boolean equals(Object other) {
10.133 if (this == other) {
10.134 return true;
10.135 @@ -572,17 +491,7 @@
10.136 if (!locale.equals(otherEntry.locale)) {
10.137 return false;
10.138 }
10.139 - //are refs (both non-null) or (both null)?
10.140 - if (loaderRef == null) {
10.141 - return otherEntry.loaderRef == null;
10.142 - }
10.143 - ClassLoader loader = loaderRef.get();
10.144 - return (otherEntry.loaderRef != null)
10.145 - // with a null reference we can no longer find
10.146 - // out which class loader was referenced; so
10.147 - // treat it as unequal
10.148 - && (loader != null)
10.149 - && (loader == otherEntry.loaderRef.get());
10.150 + return true;
10.151 } catch (NullPointerException e) {
10.152 } catch (ClassCastException e) {
10.153 }
10.154 @@ -596,19 +505,11 @@
10.155 private void calculateHashCode() {
10.156 hashCodeCache = name.hashCode() << 3;
10.157 hashCodeCache ^= locale.hashCode();
10.158 - ClassLoader loader = getLoader();
10.159 - if (loader != null) {
10.160 - hashCodeCache ^= loader.hashCode();
10.161 - }
10.162 }
10.163
10.164 public Object clone() {
10.165 try {
10.166 CacheKey clone = (CacheKey) super.clone();
10.167 - if (loaderRef != null) {
10.168 - clone.loaderRef = new LoaderReference(loaderRef.get(),
10.169 - referenceQueue, clone);
10.170 - }
10.171 // Clear the reference to a Throwable
10.172 clone.cause = null;
10.173 return clone;
10.174 @@ -651,7 +552,7 @@
10.175 l = "\"\"";
10.176 }
10.177 }
10.178 - return "CacheKey[" + name + ", lc=" + l + ", ldr=" + getLoader()
10.179 + return "CacheKey[" + name + ", lc=" + l
10.180 + "(format=" + format + ")]";
10.181 }
10.182 }
10.183 @@ -665,25 +566,6 @@
10.184 }
10.185
10.186 /**
10.187 - * References to class loaders are weak references, so that they can be
10.188 - * garbage collected when nobody else is using them. The ResourceBundle
10.189 - * class has no reason to keep class loaders alive.
10.190 - */
10.191 - private static final class LoaderReference extends WeakReference<ClassLoader>
10.192 - implements CacheKeyReference {
10.193 - private CacheKey cacheKey;
10.194 -
10.195 - LoaderReference(ClassLoader referent, ReferenceQueue q, CacheKey key) {
10.196 - super(referent, q);
10.197 - cacheKey = key;
10.198 - }
10.199 -
10.200 - public CacheKey getCacheKey() {
10.201 - return cacheKey;
10.202 - }
10.203 - }
10.204 -
10.205 - /**
10.206 * References to bundles are soft references so that they can be garbage
10.207 * collected when they have no hard references.
10.208 */
10.209 @@ -722,8 +604,6 @@
10.210 public static final ResourceBundle getBundle(String baseName)
10.211 {
10.212 return getBundleImpl(baseName, Locale.getDefault(),
10.213 - /* must determine loader here, else we break stack invariant */
10.214 - getLoader(),
10.215 Control.INSTANCE);
10.216 }
10.217
10.218 @@ -765,7 +645,6 @@
10.219 Control control) {
10.220 return getBundleImpl(baseName, Locale.getDefault(),
10.221 /* must determine loader here, else we break stack invariant */
10.222 - getLoader(),
10.223 control);
10.224 }
10.225
10.226 @@ -795,7 +674,6 @@
10.227 {
10.228 return getBundleImpl(baseName, locale,
10.229 /* must determine loader here, else we break stack invariant */
10.230 - getLoader(),
10.231 Control.INSTANCE);
10.232 }
10.233
10.234 @@ -840,7 +718,6 @@
10.235 Control control) {
10.236 return getBundleImpl(baseName, targetLocale,
10.237 /* must determine loader here, else we break stack invariant */
10.238 - getLoader(),
10.239 control);
10.240 }
10.241
10.242 @@ -1025,7 +902,7 @@
10.243 if (loader == null) {
10.244 throw new NullPointerException();
10.245 }
10.246 - return getBundleImpl(baseName, locale, loader, Control.INSTANCE);
10.247 + return getBundleImpl(baseName, locale, Control.INSTANCE);
10.248 }
10.249
10.250 /**
10.251 @@ -1243,11 +1120,11 @@
10.252 if (loader == null || control == null) {
10.253 throw new NullPointerException();
10.254 }
10.255 - return getBundleImpl(baseName, targetLocale, loader, control);
10.256 + return getBundleImpl(baseName, targetLocale, control);
10.257 }
10.258
10.259 private static ResourceBundle getBundleImpl(String baseName, Locale locale,
10.260 - ClassLoader loader, Control control) {
10.261 + Control control) {
10.262 if (locale == null || control == null) {
10.263 throw new NullPointerException();
10.264 }
10.265 @@ -1256,7 +1133,7 @@
10.266 // name and loader will never change during the bundle loading
10.267 // process. We have to make sure that the locale is set before
10.268 // using it as a cache key.
10.269 - CacheKey cacheKey = new CacheKey(baseName, locale, loader);
10.270 + CacheKey cacheKey = new CacheKey(baseName, locale);
10.271 ResourceBundle bundle = null;
10.272
10.273 // Quick lookup of the cache.
10.274 @@ -1388,7 +1265,7 @@
10.275 // the same bundles having different parents.
10.276 BundleReference bundleRef = cacheList.get(cacheKey);
10.277 if (bundleRef != null && bundleRef.get() == bundle) {
10.278 - cacheList.remove(cacheKey, bundleRef);
10.279 + cacheList.remove(cacheKey);
10.280 }
10.281 }
10.282 }
10.283 @@ -1434,7 +1311,7 @@
10.284 String format = formats.get(i);
10.285 try {
10.286 bundle = control.newBundle(cacheKey.getName(), targetLocale, format,
10.287 - cacheKey.getLoader(), reload);
10.288 + null, reload);
10.289 } catch (LinkageError error) {
10.290 // We need to handle the LinkageError case due to
10.291 // inconsistent case-sensitivity in ClassLoader.
10.292 @@ -1562,7 +1439,7 @@
10.293 assert bundle != NONEXISTENT_BUNDLE;
10.294 bundle.expired = true;
10.295 bundle.cacheKey = null;
10.296 - cacheList.remove(cacheKey, bundleRef);
10.297 + cacheList.remove(cacheKey);
10.298 bundle = null;
10.299 } else {
10.300 CacheKey key = bundleRef.getCacheKey();
10.301 @@ -1581,7 +1458,7 @@
10.302 bundle.expired = control.needsReload(key.getName(),
10.303 key.getLocale(),
10.304 key.getFormat(),
10.305 - key.getLoader(),
10.306 + null,
10.307 bundle,
10.308 key.loadTime);
10.309 } catch (Exception e) {
10.310 @@ -1593,7 +1470,7 @@
10.311 // return the bundle with the expired flag
10.312 // on.
10.313 bundle.cacheKey = null;
10.314 - cacheList.remove(cacheKey, bundleRef);
10.315 + cacheList.remove(cacheKey);
10.316 } else {
10.317 // Update the expiration control info. and reuse
10.318 // the same bundle instance
10.319 @@ -1603,7 +1480,7 @@
10.320 }
10.321 } else {
10.322 // We just remove NONEXISTENT_BUNDLE from the cache.
10.323 - cacheList.remove(cacheKey, bundleRef);
10.324 + cacheList.remove(cacheKey);
10.325 bundle = null;
10.326 }
10.327 }
10.328 @@ -1630,7 +1507,7 @@
10.329 bundle.cacheKey = key;
10.330
10.331 // Put the bundle in the cache if it's not been in the cache.
10.332 - BundleReference result = cacheList.putIfAbsent(key, bundleRef);
10.333 + BundleReference result = cacheList.put(key, bundleRef);
10.334
10.335 // If someone else has put the same bundle in the cache before
10.336 // us and it has not expired, we should use the one in the cache.
10.337 @@ -1677,7 +1554,7 @@
10.338 * @see ResourceBundle.Control#getTimeToLive(String,Locale)
10.339 */
10.340 public static final void clearCache() {
10.341 - clearCache(getLoader());
10.342 + clearCache(null);
10.343 }
10.344
10.345 /**
10.346 @@ -1695,9 +1572,7 @@
10.347 }
10.348 Set<CacheKey> set = cacheList.keySet();
10.349 for (CacheKey key : set) {
10.350 - if (key.getLoader() == loader) {
10.351 - set.remove(key);
10.352 - }
10.353 + set.remove(key);
10.354 }
10.355 }
10.356
10.357 @@ -2300,13 +2175,25 @@
10.358 if (baseName == null) {
10.359 throw new NullPointerException();
10.360 }
10.361 - return new ArrayList<>(CANDIDATES_CACHE.get(locale.getBaseLocale()));
10.362 + return new ArrayList<>(CANDIDATES_CACHE.get(locale));
10.363 }
10.364
10.365 private static final CandidateListCache CANDIDATES_CACHE = new CandidateListCache();
10.366
10.367 - private static class CandidateListCache extends LocaleObjectCache<BaseLocale, List<Locale>> {
10.368 - protected List<Locale> createObject(BaseLocale base) {
10.369 + private static class CandidateListCache {
10.370 + private Locale prevQuery;
10.371 + private List<Locale> prevResult;
10.372 +
10.373 + public List<Locale> get(Locale l) {
10.374 + if (prevQuery == l) {
10.375 + return prevResult;
10.376 + }
10.377 + prevResult = createObject(l);
10.378 + prevQuery = l;
10.379 + return prevResult;
10.380 + }
10.381 +
10.382 + protected List<Locale> createObject(Locale base) {
10.383 String language = base.getLanguage();
10.384 String script = base.getScript();
10.385 String region = base.getRegion();
10.386 @@ -2563,7 +2450,9 @@
10.387 if (format.equals("java.class")) {
10.388 try {
10.389 Class<? extends ResourceBundle> bundleClass
10.390 - = (Class<? extends ResourceBundle>)loader.loadClass(bundleName);
10.391 + = (Class<? extends ResourceBundle>)(loader != null ?
10.392 + loader.loadClass(bundleName) :
10.393 + Class.forName(bundleName));
10.394
10.395 // If the class isn't a ResourceBundle subclass, throw a
10.396 // ClassCastException.
10.397 @@ -2579,39 +2468,15 @@
10.398 final String resourceName = toResourceName(bundleName, "properties");
10.399 final ClassLoader classLoader = loader;
10.400 final boolean reloadFlag = reload;
10.401 - InputStream stream = null;
10.402 - try {
10.403 - stream = AccessController.doPrivileged(
10.404 - new PrivilegedExceptionAction<InputStream>() {
10.405 - public InputStream run() throws IOException {
10.406 - InputStream is = null;
10.407 - if (reloadFlag) {
10.408 - URL url = classLoader.getResource(resourceName);
10.409 - if (url != null) {
10.410 - URLConnection connection = url.openConnection();
10.411 - if (connection != null) {
10.412 - // Disable caches to get fresh data for
10.413 - // reloading.
10.414 - connection.setUseCaches(false);
10.415 - is = connection.getInputStream();
10.416 - }
10.417 - }
10.418 - } else {
10.419 - is = classLoader.getResourceAsStream(resourceName);
10.420 - }
10.421 - return is;
10.422 - }
10.423 - });
10.424 - } catch (PrivilegedActionException e) {
10.425 - throw (IOException) e.getException();
10.426 - }
10.427 + InputStream stream = classLoader != null ? classLoader.getResourceAsStream(resourceName) :
10.428 + ResourceBundle.class.getResourceAsStream("/" + resourceName);
10.429 if (stream != null) {
10.430 try {
10.431 bundle = new PropertyResourceBundle(stream);
10.432 } finally {
10.433 stream.close();
10.434 }
10.435 - }
10.436 + }
10.437 } else {
10.438 throw new IllegalArgumentException("unknown format: " + format);
10.439 }
10.440 @@ -2730,6 +2595,7 @@
10.441 }
10.442 boolean result = false;
10.443 try {
10.444 +/*
10.445 String resourceName = toResourceName(toBundleName(baseName, locale), format);
10.446 URL url = loader.getResource(resourceName);
10.447 if (url != null) {
10.448 @@ -2752,6 +2618,7 @@
10.449 }
10.450 result = lastModified >= loadTime;
10.451 }
10.452 + */
10.453 } catch (NullPointerException npe) {
10.454 throw npe;
10.455 } catch (Exception e) {
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ResourceBundleTest.java Thu Oct 03 17:36:44 2013 +0200
11.3 @@ -0,0 +1,46 @@
11.4 +/**
11.5 + * Back 2 Browser Bytecode Translator
11.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
11.7 + *
11.8 + * This program is free software: you can redistribute it and/or modify
11.9 + * it under the terms of the GNU General Public License as published by
11.10 + * the Free Software Foundation, version 2 of the License.
11.11 + *
11.12 + * This program is distributed in the hope that it will be useful,
11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11.15 + * GNU General Public License for more details.
11.16 + *
11.17 + * You should have received a copy of the GNU General Public License
11.18 + * along with this program. Look for COPYING file in the top folder.
11.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
11.20 + */
11.21 +package org.apidesign.bck2brwsr.tck;
11.22 +
11.23 +import java.io.InputStream;
11.24 +import java.net.URL;
11.25 +import java.util.ResourceBundle;
11.26 +import org.apidesign.bck2brwsr.vmtest.Compare;
11.27 +import org.apidesign.bck2brwsr.vmtest.VMTest;
11.28 +import org.testng.annotations.Factory;
11.29 +
11.30 +/**
11.31 + *
11.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
11.33 + */
11.34 +public class ResourceBundleTest {
11.35 +
11.36 + @Compare public String readFromBundle() throws Exception {
11.37 + ResourceBundle b = ResourceBundle.getBundle("org/apidesign/bck2brwsr/tck/Bundle");
11.38 + return b.getString("KEY");
11.39 + }
11.40 +
11.41 + @Compare public String toURIFromURL() throws Exception {
11.42 + URL u = new URL("http://apidesign.org");
11.43 + return u.toURI().toString();
11.44 + }
11.45 +
11.46 + @Factory public static Object[] create() {
11.47 + return VMTest.create(ResourceBundleTest.class);
11.48 + }
11.49 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/rt/emul/compact/src/test/resources/org/apidesign/bck2brwsr/tck/Bundle.properties Thu Oct 03 17:36:44 2013 +0200
12.3 @@ -0,0 +1,2 @@
12.4 +KEY=Value
12.5 +