diff options
Diffstat (limited to 'libjava/classpath/java/util')
-rw-r--r-- | libjava/classpath/java/util/Formatter.java | 2 | ||||
-rw-r--r-- | libjava/classpath/java/util/HashMap.java | 10 | ||||
-rw-r--r-- | libjava/classpath/java/util/logging/LogManager.java | 27 | ||||
-rw-r--r-- | libjava/classpath/java/util/regex/Matcher.java | 29 | ||||
-rw-r--r-- | libjava/classpath/java/util/regex/Pattern.java | 40 | ||||
-rw-r--r-- | libjava/classpath/java/util/zip/InflaterHuffmanTree.java | 7 | ||||
-rw-r--r-- | libjava/classpath/java/util/zip/ZipFile.java | 5 |
7 files changed, 108 insertions, 12 deletions
diff --git a/libjava/classpath/java/util/Formatter.java b/libjava/classpath/java/util/Formatter.java index 04ae8058dcf..62f68456239 100644 --- a/libjava/classpath/java/util/Formatter.java +++ b/libjava/classpath/java/util/Formatter.java @@ -1188,7 +1188,7 @@ public final class Formatter advance(); if (start == index) return -1; - return Integer.decode(format.substring(start, index)); + return Integer.parseInt(format.substring(start, index)); } /** diff --git a/libjava/classpath/java/util/HashMap.java b/libjava/classpath/java/util/HashMap.java index 55d81c620b1..f5194a24061 100644 --- a/libjava/classpath/java/util/HashMap.java +++ b/libjava/classpath/java/util/HashMap.java @@ -100,11 +100,10 @@ public class HashMap<K, V> extends AbstractMap<K, V> implements Map<K, V>, Cloneable, Serializable { /** - * Default number of buckets. This is the value the JDK 1.3 uses. Some - * early documentation specified this value as 101. That is incorrect. + * Default number of buckets; this is currently set to 16. * Package visible for use by HashSet. */ - static final int DEFAULT_CAPACITY = 11; + static final int DEFAULT_CAPACITY = 16; /** * The default load factor; this is explicitly specified by the spec. @@ -344,9 +343,12 @@ public class HashMap<K, V> extends AbstractMap<K, V> int idx = hash(key); HashEntry<K, V> e = buckets[idx]; + int hash1 = key == null ? 0 : key.hashCode(); while (e != null) { - if (equals(key, e.key)) + int hash2 = e.key == null ? 0 : e.key.hashCode(); + + if ((hash1 == hash2) && equals(key, e.key)) { e.access(); // Must call this for bookkeeping in LinkedHashMap. V r = e.value; diff --git a/libjava/classpath/java/util/logging/LogManager.java b/libjava/classpath/java/util/logging/LogManager.java index dffa44d9cf0..f8c6c3393fc 100644 --- a/libjava/classpath/java/util/logging/LogManager.java +++ b/libjava/classpath/java/util/logging/LogManager.java @@ -211,11 +211,21 @@ public class LogManager /** * Registers a listener which will be notified when the * logging properties are re-read. + * + * @param listener the event listener to register. + * @throws NullPointerException if the listener is {@code null}. + * @throws SecurityException if a security manager exists and the + * calling code does not have the permission + * {@code LoggingPermission("control")}. */ public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { - /* do not register null. */ - listener.getClass(); + if (listener == null) + throw new NullPointerException("Attempt to add null property change listener"); + + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkPermission(new LoggingPermission("control", null)); pcs.addPropertyChangeListener(listener); } @@ -226,11 +236,22 @@ public class LogManager * If <code>listener</code> has not been registered previously, * nothing happens. Also, no exception is thrown if * <code>listener</code> is <code>null</code>. + * + * @param listener the listener to remove. + * @throws SecurityException if a security manager exists and the + * calling code does not have the permission + * {@code LoggingPermission("control")}. */ public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { if (listener != null) - pcs.removePropertyChangeListener(listener); + { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkPermission(new LoggingPermission("control", null)); + + pcs.removePropertyChangeListener(listener); + } } /** diff --git a/libjava/classpath/java/util/regex/Matcher.java b/libjava/classpath/java/util/regex/Matcher.java index be57471de61..8d033d5e316 100644 --- a/libjava/classpath/java/util/regex/Matcher.java +++ b/libjava/classpath/java/util/regex/Matcher.java @@ -169,6 +169,12 @@ public final class Matcher implements MatchResult if (match != null) { int endIndex = match.getEndIndex(); + // Is the match within input limits? + if (endIndex > input.length()) + { + match = null; + return false; + } // Are we stuck at the same position? if (!first && endIndex == position) { @@ -608,4 +614,27 @@ public final class Matcher implements MatchResult return snapshot; } + /** + * Returns a literalized string of s where characters {@code $} and {@code + * \\} are escaped. + * + * @param s the string to literalize. + * @return the literalized string. + * @since 1.5 + */ + public static String quoteReplacement(String s) + { + if (s == null) + throw new NullPointerException(); + CPStringBuilder sb = new CPStringBuilder(); + for (int i = 0; i < s.length(); i++) + { + char ch = s.charAt(i); + if (ch == '$' || ch == '\\') + sb.append('\\'); + sb.append(ch); + } + return sb.toString(); + } + } diff --git a/libjava/classpath/java/util/regex/Pattern.java b/libjava/classpath/java/util/regex/Pattern.java index 7d1fc84b4e6..b1c937f7815 100644 --- a/libjava/classpath/java/util/regex/Pattern.java +++ b/libjava/classpath/java/util/regex/Pattern.java @@ -1,5 +1,6 @@ /* Pattern.java -- Compiled regular expression ready to be applied. - Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005, 2007, 2010 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,6 +38,8 @@ exception statement from your version. */ package java.util.regex; +import gnu.java.lang.CPStringBuilder; + import gnu.java.util.regex.RE; import gnu.java.util.regex.REException; import gnu.java.util.regex.RESyntax; @@ -260,6 +263,41 @@ public final class Pattern implements Serializable } /** + * Returns a literal pattern for the specified String. + * + * @param String to return a literal pattern for. + * @return a literal pattern for the specified String. + * @exception NullPointerException if str is null. + * @since 1.5 + */ + public static String quote(String str) + { + int eInd = str.indexOf("\\E"); + if (eInd < 0) + { + // No need to handle backslashes. + return "\\Q" + str + "\\E"; + } + + CPStringBuilder sb = new CPStringBuilder(str.length() + 16); + sb.append("\\Q"); // start quote + + int pos = 0; + do + { + // A backslash is quoted by another backslash; + // 'E' is not needed to be quoted. + sb.append(str.substring(pos, eInd)) + .append("\\E" + "\\\\" + "E" + "\\Q"); + pos = eInd + 2; + } while ((eInd = str.indexOf("\\E", pos)) >= 0); + + sb.append(str.substring(pos, str.length())) + .append("\\E"); // end quote + return sb.toString(); + } + + /** * Return the regular expression used to construct this object. * @specnote Prior to JDK 1.5 this method had a different behavior * @since 1.5 diff --git a/libjava/classpath/java/util/zip/InflaterHuffmanTree.java b/libjava/classpath/java/util/zip/InflaterHuffmanTree.java index c12c732e0c7..1a152d2b29b 100644 --- a/libjava/classpath/java/util/zip/InflaterHuffmanTree.java +++ b/libjava/classpath/java/util/zip/InflaterHuffmanTree.java @@ -95,11 +95,14 @@ class InflaterHuffmanTree blCount[bits]++; } + int max = 0; int code = 0; int treeSize = 512; for (int bits = 1; bits <= MAX_BITLEN; bits++) { nextCode[bits] = code; + if (blCount[bits] > 0) + max = bits; code += blCount[bits] << (16 - bits); if (bits >= 10) { @@ -109,8 +112,8 @@ class InflaterHuffmanTree treeSize += (end - start) >> (16 - bits); } } - if (code != 65536) - throw new DataFormatException("Code lengths don't add up properly."); + if (code != 65536 && max > 1) + throw new DataFormatException("incomplete dynamic bit lengths tree"); /* Now create and fill the extra tables from longest to shortest * bit len. This way the sub trees will be aligned. diff --git a/libjava/classpath/java/util/zip/ZipFile.java b/libjava/classpath/java/util/zip/ZipFile.java index 3963bcb1eb5..b582c84939c 100644 --- a/libjava/classpath/java/util/zip/ZipFile.java +++ b/libjava/classpath/java/util/zip/ZipFile.java @@ -261,7 +261,10 @@ public class ZipFile implements ZipConstants if (inp.readLeInt() != CENSIG) throw new ZipException("Wrong Central Directory signature: " + name); - inp.skip(6); + inp.skip(4); + int flags = inp.readLeShort(); + if ((flags & 1) != 0) + throw new ZipException("invalid CEN header (encrypted entry)"); int method = inp.readLeShort(); int dostime = inp.readLeInt(); int crc = inp.readLeInt(); |