Skip to content

Commit

Permalink
Chasing down more low-hanging findbugs bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Mar 3, 2011
1 parent 0e23c6b commit b5d61f3
Show file tree
Hide file tree
Showing 31 changed files with 509 additions and 563 deletions.
4 changes: 2 additions & 2 deletions src/com/mysql/jdbc/BlobFromLocator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
Expand Down Expand Up @@ -587,7 +587,7 @@ class LocatorInputStream extends InputStream {
if (pos + len > blobLength) {
throw SQLError.createSQLException(
Messages.getString("Blob.invalidStreamLength",
new Object[] {new Long(blobLength), new Long(pos), new Long(len)}),
new Object[] {Long.valueOf(blobLength), Long.valueOf(pos), Long.valueOf(len)}),
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
}

Expand Down
78 changes: 39 additions & 39 deletions src/com/mysql/jdbc/CharsetMapping.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
Expand Down Expand Up @@ -80,43 +80,43 @@ public class CharsetMapping {
static {
HashMap tempNumBytesMap = new HashMap();

tempNumBytesMap.put("big5", Constants.integerValueOf(2));
tempNumBytesMap.put("dec8" , Constants.integerValueOf(1));
tempNumBytesMap.put("cp850", Constants.integerValueOf(1));
tempNumBytesMap.put("hp8", Constants.integerValueOf(1));
tempNumBytesMap.put("koi8r", Constants.integerValueOf(1));
tempNumBytesMap.put("latin1", Constants.integerValueOf(1));
tempNumBytesMap.put("latin2", Constants.integerValueOf(1));
tempNumBytesMap.put("swe7", Constants.integerValueOf(1));
tempNumBytesMap.put("ascii", Constants.integerValueOf(1));
tempNumBytesMap.put("ujis", Constants.integerValueOf(3));
tempNumBytesMap.put("sjis", Constants.integerValueOf(2));
tempNumBytesMap.put("hebrew", Constants.integerValueOf(1));
tempNumBytesMap.put("tis620", Constants.integerValueOf(1));
tempNumBytesMap.put("euckr", Constants.integerValueOf(2));
tempNumBytesMap.put("koi8u", Constants.integerValueOf(1));
tempNumBytesMap.put("gb2312", Constants.integerValueOf(2));
tempNumBytesMap.put("greek", Constants.integerValueOf(1));
tempNumBytesMap.put("cp1250", Constants.integerValueOf(1));
tempNumBytesMap.put("gbk", Constants.integerValueOf(2));
tempNumBytesMap.put("latin5", Constants.integerValueOf(1));
tempNumBytesMap.put("armscii8", Constants.integerValueOf(1));
tempNumBytesMap.put("utf8", Constants.integerValueOf(3));
tempNumBytesMap.put("ucs2", Constants.integerValueOf(2));
tempNumBytesMap.put("cp866", Constants.integerValueOf(1));
tempNumBytesMap.put("keybcs2", Constants.integerValueOf(1));
tempNumBytesMap.put("macce", Constants.integerValueOf(1));
tempNumBytesMap.put("macroman", Constants.integerValueOf(1));
tempNumBytesMap.put("cp852" , Constants.integerValueOf(1));
tempNumBytesMap.put("latin7", Constants.integerValueOf(1));
tempNumBytesMap.put("cp1251", Constants.integerValueOf(1));
tempNumBytesMap.put("cp1256" , Constants.integerValueOf(1));
tempNumBytesMap.put("cp1257", Constants.integerValueOf(1));
tempNumBytesMap.put("binary", Constants.integerValueOf(1));
tempNumBytesMap.put("geostd8", Constants.integerValueOf(1));
tempNumBytesMap.put("cp932", Constants.integerValueOf(2));
tempNumBytesMap.put("eucjpms", Constants.integerValueOf(3));
tempNumBytesMap.put("utf8mb4", Constants.integerValueOf(4));
tempNumBytesMap.put("big5", Integer.valueOf(2));
tempNumBytesMap.put("dec8" , Integer.valueOf(1));
tempNumBytesMap.put("cp850", Integer.valueOf(1));
tempNumBytesMap.put("hp8", Integer.valueOf(1));
tempNumBytesMap.put("koi8r", Integer.valueOf(1));
tempNumBytesMap.put("latin1", Integer.valueOf(1));
tempNumBytesMap.put("latin2", Integer.valueOf(1));
tempNumBytesMap.put("swe7", Integer.valueOf(1));
tempNumBytesMap.put("ascii", Integer.valueOf(1));
tempNumBytesMap.put("ujis", Integer.valueOf(3));
tempNumBytesMap.put("sjis", Integer.valueOf(2));
tempNumBytesMap.put("hebrew", Integer.valueOf(1));
tempNumBytesMap.put("tis620", Integer.valueOf(1));
tempNumBytesMap.put("euckr", Integer.valueOf(2));
tempNumBytesMap.put("koi8u", Integer.valueOf(1));
tempNumBytesMap.put("gb2312", Integer.valueOf(2));
tempNumBytesMap.put("greek", Integer.valueOf(1));
tempNumBytesMap.put("cp1250", Integer.valueOf(1));
tempNumBytesMap.put("gbk", Integer.valueOf(2));
tempNumBytesMap.put("latin5", Integer.valueOf(1));
tempNumBytesMap.put("armscii8", Integer.valueOf(1));
tempNumBytesMap.put("utf8", Integer.valueOf(3));
tempNumBytesMap.put("ucs2", Integer.valueOf(2));
tempNumBytesMap.put("cp866", Integer.valueOf(1));
tempNumBytesMap.put("keybcs2", Integer.valueOf(1));
tempNumBytesMap.put("macce", Integer.valueOf(1));
tempNumBytesMap.put("macroman", Integer.valueOf(1));
tempNumBytesMap.put("cp852" , Integer.valueOf(1));
tempNumBytesMap.put("latin7", Integer.valueOf(1));
tempNumBytesMap.put("cp1251", Integer.valueOf(1));
tempNumBytesMap.put("cp1256" , Integer.valueOf(1));
tempNumBytesMap.put("cp1257", Integer.valueOf(1));
tempNumBytesMap.put("binary", Integer.valueOf(1));
tempNumBytesMap.put("geostd8", Integer.valueOf(1));
tempNumBytesMap.put("cp932", Integer.valueOf(2));
tempNumBytesMap.put("eucjpms", Integer.valueOf(3));
tempNumBytesMap.put("utf8mb4", Integer.valueOf(4));

STATIC_CHARSET_TO_NUM_BYTES_MAP = Collections.unmodifiableMap(
tempNumBytesMap);
Expand Down Expand Up @@ -820,7 +820,7 @@ public class CharsetMapping {
String mysqlEncodingName = INDEX_TO_CHARSET[i];

if (mysqlEncodingName != null) {
indexMap.put(INDEX_TO_CHARSET[i], Constants.integerValueOf(i));
indexMap.put(INDEX_TO_CHARSET[i], Integer.valueOf(i));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/com/mysql/jdbc/ConnectionGroup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand Down Expand Up @@ -57,7 +57,7 @@ public long registerConnectionProxy(LoadBalancingConnectionProxy proxy, List<Str
this.activeHosts = localHostList.size();
}
currentConnectionId = ++connections;
this.connectionProxies.put(new Long(currentConnectionId), proxy);
this.connectionProxies.put(Long.valueOf(currentConnectionId), proxy);
}
this.activeConnections++;

Expand Down Expand Up @@ -163,7 +163,7 @@ public long getTotalTransactionCount(){

public void closeConnectionProxy(LoadBalancingConnectionProxy proxy){
this.activeConnections--;
this.connectionProxies.remove(new Long(proxy.getConnectionGroupProxyID()));
this.connectionProxies.remove(Long.valueOf(proxy.getConnectionGroupProxyID()));
this.closedProxyTotalPhysicalConnections += proxy.getTotalPhysicalConnectionCount();
this.closedProxyTotalTransactions += proxy.getTransactionCount();

Expand Down
6 changes: 3 additions & 3 deletions src/com/mysql/jdbc/ConnectionGroupManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand Down Expand Up @@ -177,9 +177,9 @@ public static String getActiveHostLists(String group) {
String host = j.next().toString();
Object o = hosts.get(host);
if(o == null){
o = new Integer(1);
o = Integer.valueOf(1);
} else {
o = new Integer(((Integer) o).intValue() + 1);
o = Integer.valueOf(((Integer) o).intValue() + 1);
}
hosts.put(host, o);

Expand Down
16 changes: 8 additions & 8 deletions src/com/mysql/jdbc/ConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ public int hashCode() {

static {
mapTransIsolationNameToValue = new HashMap(8);
mapTransIsolationNameToValue.put("READ-UNCOMMITED", Constants.integerValueOf(
mapTransIsolationNameToValue.put("READ-UNCOMMITED", Integer.valueOf(
TRANSACTION_READ_UNCOMMITTED));
mapTransIsolationNameToValue.put("READ-UNCOMMITTED", Constants.integerValueOf(
mapTransIsolationNameToValue.put("READ-UNCOMMITTED", Integer.valueOf(
TRANSACTION_READ_UNCOMMITTED));
mapTransIsolationNameToValue.put("READ-COMMITTED", Constants.integerValueOf(
mapTransIsolationNameToValue.put("READ-COMMITTED", Integer.valueOf(
TRANSACTION_READ_COMMITTED));
mapTransIsolationNameToValue.put("REPEATABLE-READ", Constants.integerValueOf(
mapTransIsolationNameToValue.put("REPEATABLE-READ", Integer.valueOf(
TRANSACTION_REPEATABLE_READ));
mapTransIsolationNameToValue.put("SERIALIZABLE", Constants.integerValueOf(
mapTransIsolationNameToValue.put("SERIALIZABLE", Integer.valueOf(
TRANSACTION_SERIALIZABLE));

if (Util.isJdbc4()) {
Expand Down Expand Up @@ -378,7 +378,7 @@ protected static Connection getInstance(String hostToConnectTo,

return (Connection) Util.handleNewInstance(JDBC_4_CONNECTION_CTOR,
new Object[] {
hostToConnectTo, Constants.integerValueOf(portToConnectTo), info,
hostToConnectTo, Integer.valueOf(portToConnectTo), info,
databaseToConnectTo, url }, null);
}

Expand Down Expand Up @@ -948,7 +948,7 @@ private void buildCollationMapping() throws SQLException {

while (results.next()) {
String charsetName = results.getString(2);
Integer charsetIndex = Constants.integerValueOf(results.getInt(3));
Integer charsetIndex = Integer.valueOf(results.getInt(3));

sortedCollationMap.put(charsetIndex, charsetName);
}
Expand Down Expand Up @@ -3003,7 +3003,7 @@ public int getMaxBytesPerChar(String javaCharsetName)

while (rs.next()) {
this.charsetToNumBytesMap.put(rs.getString("Charset"),
Constants.integerValueOf(rs.getInt("Maxlen")));
Integer.valueOf(rs.getInt("Maxlen")));
}

rs.close();
Expand Down
20 changes: 10 additions & 10 deletions src/com/mysql/jdbc/ConnectionPropertiesImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
Expand Down Expand Up @@ -331,7 +331,7 @@ public IntegerConnectionProperty(String propertyNameToSet,
int defaultValueToSet, int lowerBoundToSet,
int upperBoundToSet, String descriptionToSet,
String sinceVersionToSet, String category, int orderInCategory) {
super(propertyNameToSet, new Integer(defaultValueToSet), null,
super(propertyNameToSet, Integer.valueOf(defaultValueToSet), null,
lowerBoundToSet, upperBoundToSet, descriptionToSet,
sinceVersionToSet, category, orderInCategory);
}
Expand Down Expand Up @@ -403,7 +403,7 @@ void initializeFrom(String extractedValue) throws SQLException {
* the value '" + extractedValue + "' exceeds this range.",
* SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } }
*/
this.valueAsObject = new Integer(intValue * multiplier);
this.valueAsObject = Integer.valueOf(intValue * multiplier);
} catch (NumberFormatException nfe) {
throw SQLError.createSQLException("The connection property '" //$NON-NLS-1$
+ getPropertyName()
Expand All @@ -425,7 +425,7 @@ boolean isRangeBased() {
}

void setValue(int valueFlag) {
this.valueAsObject = new Integer(valueFlag);
this.valueAsObject = Integer.valueOf(valueFlag);
}
}

Expand All @@ -437,7 +437,7 @@ public class LongConnectionProperty extends IntegerConnectionProperty {
long defaultValueToSet, long lowerBoundToSet,
long upperBoundToSet, String descriptionToSet,
String sinceVersionToSet, String category, int orderInCategory) {
super(propertyNameToSet, new Long(defaultValueToSet), null,
super(propertyNameToSet, Long.valueOf(defaultValueToSet), null,
(int)lowerBoundToSet, (int)upperBoundToSet, descriptionToSet,
sinceVersionToSet, category, orderInCategory);
}
Expand All @@ -453,7 +453,7 @@ public class LongConnectionProperty extends IntegerConnectionProperty {
}

void setValue(long value) {
this.valueAsObject = new Long(value);
this.valueAsObject = Long.valueOf(value);
}

long getValueAsLong() {
Expand All @@ -466,7 +466,7 @@ void initializeFrom(String extractedValue) throws SQLException {
// Parse decimals, too
long longValue = Double.valueOf(extractedValue).longValue();

this.valueAsObject = new Long(longValue);
this.valueAsObject = Long.valueOf(longValue);
} catch (NumberFormatException nfe) {
throw SQLError.createSQLException("The connection property '" //$NON-NLS-1$
+ getPropertyName()
Expand Down Expand Up @@ -1880,7 +1880,7 @@ public String exposeAsXml() throws SQLException {
TreeMap userMap = new TreeMap();
userMap.put(userProp.getPropertyName(), userProp);

connectionSortMaps[0].put(new Integer(userProp.getOrder()), userMap);
connectionSortMaps[0].put(Integer.valueOf(userProp.getOrder()), userMap);

TreeMap passwordMap = new TreeMap();
passwordMap.put(passwordProp.getPropertyName(), passwordProp);
Expand All @@ -1901,7 +1901,7 @@ public String exposeAsXml() throws SQLException {
if (orderInCategory == Integer.MIN_VALUE) {
sortMaps[1].put(propToGet.getPropertyName(), propToGet);
} else {
Integer order = new Integer(orderInCategory);
Integer order = Integer.valueOf(orderInCategory);

Map orderMap = (Map)sortMaps[0].get(order);

Expand Down Expand Up @@ -2795,7 +2795,7 @@ protected void postInitialization() throws SQLException {
if (this.getMaxRows() == 0) {
// adjust so that it will become MysqlDefs.MAX_ROWS
// in execSQL()
this.maxRows.setValueAsObject(Constants.integerValueOf(-1));
this.maxRows.setValueAsObject(Integer.valueOf(-1));
}

//
Expand Down
91 changes: 1 addition & 90 deletions src/com/mysql/jdbc/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
Expand Down Expand Up @@ -49,95 +49,6 @@ public class Constants {
public final static byte[] SPACE_STAR_SLASH_SPACE_AS_BYTES = new byte[] {
(byte) ' ', (byte) '*', (byte) '/', (byte) ' ' };

/*
* We're still stuck on JDK-1.4.2, but want the Number.valueOf() methods
*/
private static final Character[] CHARACTER_CACHE = new Character[128];

private static final int BYTE_CACHE_OFFSET = 128;

private static final Byte[] BYTE_CACHE = new Byte[256];

private static final int INTEGER_CACHE_OFFSET = 128;

private static final Integer[] INTEGER_CACHE = new Integer[256];

private static final int SHORT_CACHE_OFFSET = 128;

private static final Short[] SHORT_CACHE = new Short[256];

private static final Long[] LONG_CACHE = new Long[256];

private static final int LONG_CACHE_OFFSET = 128;

static {
for (int i = 0; i < CHARACTER_CACHE.length; i++) {
CHARACTER_CACHE[i] = new Character((char) i);
}

for (int i = 0; i < INTEGER_CACHE.length; i++) {
INTEGER_CACHE[i] = new Integer(i - 128);
}

for (int i = 0; i < SHORT_CACHE.length; i++) {
SHORT_CACHE[i] = new Short((short) (i - 128));
}

for (int i = 0; i < LONG_CACHE.length; i++) {
LONG_CACHE[i] = new Long(i - 128);
}

for (int i = 0; i < BYTE_CACHE.length; i++)
BYTE_CACHE[i] = new Byte((byte) (i - BYTE_CACHE_OFFSET));
}

/** Same behavior as JDK-1.5's Constants.characterValueOf(int) */

public static Character characterValueOf(char c) {
if (c <= 127) {
return CHARACTER_CACHE[c];
}

return new Character(c);
}

/** Same behavior as JDK-1.5's Byte.valueOf(int) */

public static final Byte byteValueOf(byte b) {
return BYTE_CACHE[b + BYTE_CACHE_OFFSET];
}

/** Same behavior as JDK-1.5's Integer.valueOf(int) */

public static final Integer integerValueOf(int i) {
if (i >= -128 && i <= 127) {
return INTEGER_CACHE[i + INTEGER_CACHE_OFFSET];
}

return new Integer(i);
}

/** Same behavior as JDK-1.5's Constants.shortValueOf(int) */

public static Short shortValueOf(short s) {

if (s >= -128 && s <= 127) {
return SHORT_CACHE[s + SHORT_CACHE_OFFSET];
}

return new Short(s);
}

/** Same behavior as JDK-1.5's Long.valueOf(int) */

public static final Long longValueOf(long l) {
if (l >= -128 && l <= 127) {
return LONG_CACHE[(int) l + LONG_CACHE_OFFSET];
}

return new Long(l);
}

/**
* Prevents instantiation
*/
Expand Down
Loading

0 comments on commit b5d61f3

Please sign in to comment.