OPENJPA-1700 FindBugs - Method invokes inefficient Number constructor; use static valueOf instead

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@955046 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2010-06-15 20:53:38 +00:00
parent 5e2f6c2288
commit 8a2b1c1f08
18 changed files with 62 additions and 62 deletions

View File

@ -89,7 +89,7 @@ public abstract class AbstractQueryCache
// Pre-load all the entity types into the HashMap to handle // Pre-load all the entity types into the HashMap to handle
// synchronization on the map efficiently // synchronization on the map efficiently
for (Object o : perTypes) for (Object o : perTypes)
entityTimestampMap.put((String)o, new Long(0)); entityTimestampMap.put((String)o, Long.valueOf(0));
} }
} }
@ -121,7 +121,7 @@ public abstract class AbstractQueryCache
Collection changedTypes = ev.getTypes(); Collection changedTypes = ev.getTypes();
HashMap<String,Long> changedClasses = HashMap<String,Long> changedClasses =
new HashMap<String,Long>(); new HashMap<String,Long>();
Long tstamp = new Long(System.currentTimeMillis()); Long tstamp = Long.valueOf(System.currentTimeMillis());
for (Object o: changedTypes) { for (Object o: changedTypes) {
String name = ((Class) o).getName(); String name = ((Class) o).getName();
if(!changedClasses.containsKey(name)) { if(!changedClasses.containsKey(name)) {

View File

@ -144,10 +144,10 @@ public class ReflectingPersistenceCapable
sm.replaceBooleanField(this, i))); sm.replaceBooleanField(this, i)));
break; break;
case JavaTypes.BYTE: case JavaTypes.BYTE:
setValue(i, o, new Byte(sm.replaceByteField(this, i))); setValue(i, o, Byte.valueOf(sm.replaceByteField(this, i)));
break; break;
case JavaTypes.CHAR: case JavaTypes.CHAR:
setValue(i, o, new Character(sm.replaceCharField(this, i))); setValue(i, o, Character.valueOf(sm.replaceCharField(this, i)));
break; break;
case JavaTypes.DOUBLE: case JavaTypes.DOUBLE:
setValue(i, o, new Double(sm.replaceDoubleField(this, i))); setValue(i, o, new Double(sm.replaceDoubleField(this, i)));
@ -156,13 +156,13 @@ public class ReflectingPersistenceCapable
setValue(i, o, new Float(sm.replaceFloatField(this, i))); setValue(i, o, new Float(sm.replaceFloatField(this, i)));
break; break;
case JavaTypes.INT: case JavaTypes.INT:
setValue(i, o, new Integer(sm.replaceIntField(this, i))); setValue(i, o, Integer.valueOf(sm.replaceIntField(this, i)));
break; break;
case JavaTypes.LONG: case JavaTypes.LONG:
setValue(i, o, new Long(sm.replaceLongField(this, i))); setValue(i, o, Long.valueOf(sm.replaceLongField(this, i)));
break; break;
case JavaTypes.SHORT: case JavaTypes.SHORT:
setValue(i, o, new Short(sm.replaceShortField(this, i))); setValue(i, o, Short.valueOf(sm.replaceShortField(this, i)));
break; break;
case JavaTypes.STRING: case JavaTypes.STRING:
setValue(i, o, sm.replaceStringField(this, i)); setValue(i, o, sm.replaceStringField(this, i));

View File

@ -779,14 +779,14 @@ public class Reflection {
* Invoke the given setter on the given object. * Invoke the given setter on the given object.
*/ */
public static void set(Object target, Method setter, byte value) { public static void set(Object target, Method setter, byte value) {
set(target, setter, new Byte(value)); set(target, setter, Byte.valueOf(value));
} }
/** /**
* Invoke the given setter on the given object. * Invoke the given setter on the given object.
*/ */
public static void set(Object target, Method setter, char value) { public static void set(Object target, Method setter, char value) {
set(target, setter, new Character(value)); set(target, setter, Character.valueOf(value));
} }
/** /**
@ -807,21 +807,21 @@ public class Reflection {
* Invoke the given setter on the given object. * Invoke the given setter on the given object.
*/ */
public static void set(Object target, Method setter, int value) { public static void set(Object target, Method setter, int value) {
set(target, setter, new Integer(value)); set(target, setter, Integer.valueOf(value));
} }
/** /**
* Invoke the given setter on the given object. * Invoke the given setter on the given object.
*/ */
public static void set(Object target, Method setter, long value) { public static void set(Object target, Method setter, long value) {
set(target, setter, new Long(value)); set(target, setter, Long.valueOf(value));
} }
/** /**
* Invoke the given setter on the given object. * Invoke the given setter on the given object.
*/ */
public static void set(Object target, Method setter, short value) { public static void set(Object target, Method setter, short value) {
set(target, setter, new Short(value)); set(target, setter, Short.valueOf(value));
} }
/** /**

View File

@ -1624,7 +1624,7 @@ public class BrokerImpl
&& (tranStatus != Status.STATUS_COMMITTED)) && (tranStatus != Status.STATUS_COMMITTED))
_runtime.setRollbackOnly(cause); _runtime.setRollbackOnly(cause);
else if (_log.isTraceEnabled()) else if (_log.isTraceEnabled())
_log.trace(_loc.get("invalid-tran-status", new Integer( _log.trace(_loc.get("invalid-tran-status", Integer.valueOf(
tranStatus), "setRollbackOnly")); tranStatus), "setRollbackOnly"));
} catch (OpenJPAException ke) { } catch (OpenJPAException ke) {
throw ke; throw ke;

View File

@ -309,9 +309,9 @@ public class DetachedValueStateManager
return (fm.fetchBooleanField(field)) ? Boolean.TRUE return (fm.fetchBooleanField(field)) ? Boolean.TRUE
: Boolean.FALSE; : Boolean.FALSE;
case JavaTypes.BYTE: case JavaTypes.BYTE:
return new Byte(fm.fetchByteField(field)); return Byte.valueOf(fm.fetchByteField(field));
case JavaTypes.CHAR: case JavaTypes.CHAR:
return new Character(fm.fetchCharField(field)); return Character.valueOf(fm.fetchCharField(field));
case JavaTypes.DOUBLE: case JavaTypes.DOUBLE:
return new Double(fm.fetchDoubleField(field)); return new Double(fm.fetchDoubleField(field));
case JavaTypes.FLOAT: case JavaTypes.FLOAT:
@ -321,7 +321,7 @@ public class DetachedValueStateManager
case JavaTypes.LONG: case JavaTypes.LONG:
return fm.fetchLongField(field); return fm.fetchLongField(field);
case JavaTypes.SHORT: case JavaTypes.SHORT:
return new Short(fm.fetchShortField(field)); return Short.valueOf(fm.fetchShortField(field));
default: default:
return fm.fetchObjectField(field); return fm.fetchObjectField(field);
} }

View File

@ -307,7 +307,7 @@ public class FetchConfigurationImpl
&& flush != QueryFlushModes.FLUSH_FALSE && flush != QueryFlushModes.FLUSH_FALSE
&& flush != QueryFlushModes.FLUSH_WITH_CONNECTION) && flush != QueryFlushModes.FLUSH_WITH_CONNECTION)
throw new IllegalArgumentException(_loc.get( throw new IllegalArgumentException(_loc.get(
"bad-flush-before-queries", new Integer(flush)).getMessage()); "bad-flush-before-queries", Integer.valueOf(flush)).getMessage());
if (flush == DEFAULT && _state.ctx != null) if (flush == DEFAULT && _state.ctx != null)
_state.flushQuery = _state.ctx.getConfiguration(). _state.flushQuery = _state.ctx.getConfiguration().
@ -549,7 +549,7 @@ public class FetchConfigurationImpl
&& scope != LockScopes.LOCKSCOPE_NORMAL && scope != LockScopes.LOCKSCOPE_NORMAL
&& scope != LockScopes.LOCKSCOPE_EXTENDED) && scope != LockScopes.LOCKSCOPE_EXTENDED)
throw new IllegalArgumentException(_loc.get( throw new IllegalArgumentException(_loc.get(
"bad-lock-scope", new Integer(scope)).getMessage()); "bad-lock-scope", Integer.valueOf(scope)).getMessage());
if (scope == DEFAULT ) if (scope == DEFAULT )
_state.lockScope = LOCKSCOPE_NORMAL; _state.lockScope = LOCKSCOPE_NORMAL;
else else
@ -575,7 +575,7 @@ public class FetchConfigurationImpl
&& level != MixedLockLevels.LOCK_PESSIMISTIC_WRITE && level != MixedLockLevels.LOCK_PESSIMISTIC_WRITE
&& level != MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT) && level != MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT)
throw new IllegalArgumentException(_loc.get( throw new IllegalArgumentException(_loc.get(
"bad-lock-level", new Integer(level)).getMessage()); "bad-lock-level", Integer.valueOf(level)).getMessage());
lock(); lock();
try { try {
@ -610,7 +610,7 @@ public class FetchConfigurationImpl
&& level != MixedLockLevels.LOCK_PESSIMISTIC_WRITE && level != MixedLockLevels.LOCK_PESSIMISTIC_WRITE
&& level != MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT) && level != MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT)
throw new IllegalArgumentException(_loc.get( throw new IllegalArgumentException(_loc.get(
"bad-lock-level", new Integer(level)).getMessage()); "bad-lock-level", Integer.valueOf(level)).getMessage());
lock(); lock();
try { try {

View File

@ -298,7 +298,7 @@ public class Filters {
else if (type == Character.class) { else if (type == Character.class) {
String str = o.toString(); String str = o.toString();
if (str != null && str.length() == 1) if (str != null && str.length() == 1)
return new Character(str.charAt(0)); return Character.valueOf(str.charAt(0));
} else if (Calendar.class.isAssignableFrom(type) && } else if (Calendar.class.isAssignableFrom(type) &&
o instanceof Date) { o instanceof Date) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
@ -359,9 +359,9 @@ public class Filters {
} else if (type == BigInteger.class) { } else if (type == BigInteger.class) {
return new BigInteger(o.toString()); return new BigInteger(o.toString());
} else if (type == Short.class && allowNumericConversion(o.getClass(), type, strictNumericConversion)) { } else if (type == Short.class && allowNumericConversion(o.getClass(), type, strictNumericConversion)) {
return new Short(((Number) o).shortValue()); return Short.valueOf(((Number) o).shortValue());
} else if (type == Byte.class && allowNumericConversion(o.getClass(), type, strictNumericConversion)) { } else if (type == Byte.class && allowNumericConversion(o.getClass(), type, strictNumericConversion)) {
return new Byte(((Number) o).byteValue()); return Byte.valueOf(((Number) o).byteValue());
} else if (!strictNumericConversion) { } else if (!strictNumericConversion) {
return ((Number) o).intValue(); return ((Number) o).intValue();
} else { } else {
@ -1017,15 +1017,15 @@ public class Filters {
public static Object getDefaultForNull(Class<?> nType) { public static Object getDefaultForNull(Class<?> nType) {
if (nType == Long.class) if (nType == Long.class)
return new Long(0); return Long.valueOf(0);
if (nType == Integer.class) if (nType == Integer.class)
return new Integer(0); return Integer.valueOf(0);
if (nType == Double.class) if (nType == Double.class)
return new Double(0.0); return new Double(0.0);
if (nType == Float.class) if (nType == Float.class)
return new Float(0.0); return new Float(0.0);
if (nType == Short.class) if (nType == Short.class)
return new Short((short)0); return Short.valueOf((short)0);
return null; return null;
} }

View File

@ -47,11 +47,11 @@ import org.apache.openjpa.util.ImplHelper;
public class ObjectIdStateManager public class ObjectIdStateManager
implements OpenJPAStateManager { implements OpenJPAStateManager {
private static final Byte ZERO_BYTE = new Byte((byte) 0); private static final Byte ZERO_BYTE = Byte.valueOf((byte)0);
private static final Character ZERO_CHAR = new Character((char) 0); private static final Character ZERO_CHAR = Character.valueOf((char)0);
private static final Double ZERO_DOUBLE = new Double(0); private static final Double ZERO_DOUBLE = new Double(0);
private static final Float ZERO_FLOAT = new Float(0); private static final Float ZERO_FLOAT = new Float(0);
private static final Short ZERO_SHORT = new Short((short) 0); private static final Short ZERO_SHORT = Short.valueOf((short)0);
private Object _oid; private Object _oid;
private final OpenJPAStateManager _owner; private final OpenJPAStateManager _owner;
@ -463,11 +463,11 @@ public class ObjectIdStateManager
} }
public void storeByte(int field, byte extVal) { public void storeByte(int field, byte extVal) {
setValue(field, new Byte(extVal), true); setValue(field, Byte.valueOf(extVal), true);
} }
public void storeChar(int field, char extVal) { public void storeChar(int field, char extVal) {
setValue(field, new Character(extVal), true); setValue(field, Character.valueOf(extVal), true);
} }
public void storeInt(int field, int extVal) { public void storeInt(int field, int extVal) {
@ -475,7 +475,7 @@ public class ObjectIdStateManager
} }
public void storeShort(int field, short extVal) { public void storeShort(int field, short extVal) {
setValue(field, new Short(extVal), true); setValue(field, Short.valueOf(extVal), true);
} }
public void storeLong(int field, long extVal) { public void storeLong(int field, long extVal) {

View File

@ -848,9 +848,9 @@ public class StateManagerImpl
return (fetchBooleanField(field)) ? Boolean.TRUE return (fetchBooleanField(field)) ? Boolean.TRUE
: Boolean.FALSE; : Boolean.FALSE;
case JavaTypes.BYTE: case JavaTypes.BYTE:
return new Byte(fetchByteField(field)); return Byte.valueOf(fetchByteField(field));
case JavaTypes.CHAR: case JavaTypes.CHAR:
return new Character(fetchCharField(field)); return Character.valueOf(fetchCharField(field));
case JavaTypes.DOUBLE: case JavaTypes.DOUBLE:
return new Double(fetchDoubleField(field)); return new Double(fetchDoubleField(field));
case JavaTypes.FLOAT: case JavaTypes.FLOAT:
@ -860,7 +860,7 @@ public class StateManagerImpl
case JavaTypes.LONG: case JavaTypes.LONG:
return fetchLongField(field); return fetchLongField(field);
case JavaTypes.SHORT: case JavaTypes.SHORT:
return new Short(fetchShortField(field)); return Short.valueOf(fetchShortField(field));
default: default:
return fetchObjectField(field); return fetchObjectField(field);
} }
@ -979,9 +979,9 @@ public class StateManagerImpl
return (fm.fetchBooleanField(field)) ? Boolean.TRUE return (fm.fetchBooleanField(field)) ? Boolean.TRUE
: Boolean.FALSE; : Boolean.FALSE;
case JavaTypes.BYTE: case JavaTypes.BYTE:
return new Byte(fm.fetchByteField(field)); return Byte.valueOf(fm.fetchByteField(field));
case JavaTypes.CHAR: case JavaTypes.CHAR:
return new Character(fm.fetchCharField(field)); return Character.valueOf(fm.fetchCharField(field));
case JavaTypes.DOUBLE: case JavaTypes.DOUBLE:
return new Double(fm.fetchDoubleField(field)); return new Double(fm.fetchDoubleField(field));
case JavaTypes.FLOAT: case JavaTypes.FLOAT:
@ -991,7 +991,7 @@ public class StateManagerImpl
case JavaTypes.LONG: case JavaTypes.LONG:
return fm.fetchLongField(field); return fm.fetchLongField(field);
case JavaTypes.SHORT: case JavaTypes.SHORT:
return new Short(fm.fetchShortField(field)); return Short.valueOf(fm.fetchShortField(field));
case JavaTypes.STRING: case JavaTypes.STRING:
return fm.fetchStringField(field); return fm.fetchStringField(field);
default: default:
@ -2444,7 +2444,7 @@ public class StateManagerImpl
if (!fmd.isExternalized()) if (!fmd.isExternalized())
storeByteField(field, externalVal); storeByteField(field, externalVal);
else else
storeField(field, fmd.getFieldValue(new Byte(externalVal), storeField(field, fmd.getFieldValue(Byte.valueOf(externalVal),
_broker)); _broker));
} }
@ -2465,7 +2465,7 @@ public class StateManagerImpl
if (!fmd.isExternalized()) if (!fmd.isExternalized())
storeCharField(field, externalVal); storeCharField(field, externalVal);
else else
storeField(field, fmd.getFieldValue(new Character(externalVal), storeField(field, fmd.getFieldValue(Character.valueOf(externalVal),
_broker)); _broker));
} }
@ -2592,7 +2592,7 @@ public class StateManagerImpl
if (!fmd.isExternalized()) if (!fmd.isExternalized())
storeShortField(field, externalVal); storeShortField(field, externalVal);
else else
storeField(field, fmd.getFieldValue(new Short(externalVal), storeField(field, fmd.getFieldValue(Short.valueOf(externalVal),
_broker)); _broker));
} }

View File

@ -1008,7 +1008,7 @@ public class JPQLExpressionBuilder
? node.text.substring(0, node.text.length() - 1) ? node.text.substring(0, node.text.length() - 1)
: node.text). : node.text).
multiply(new BigDecimal(negative(node))); multiply(new BigDecimal(negative(node)));
return factory.newLiteral(new Long(intlit.longValue()), return factory.newLiteral(Long.valueOf(intlit.longValue()),
Literal.TYPE_NUMBER); Literal.TYPE_NUMBER);
case JJTDECIMALLITERAL: case JJTDECIMALLITERAL:
@ -1431,13 +1431,13 @@ public class JPQLExpressionBuilder
// optimize SQL for the common case of two literals // optimize SQL for the common case of two literals
long jpqlStart = ((Number) ((Literal) val2).getValue()) long jpqlStart = ((Number) ((Literal) val2).getValue())
.longValue(); .longValue();
start = factory.newLiteral(new Long(jpqlStart - 1), start = factory.newLiteral(Long.valueOf(jpqlStart - 1),
Literal.TYPE_NUMBER); Literal.TYPE_NUMBER);
if (val3 != null) { if (val3 != null) {
long length = ((Number) ((Literal) val3).getValue()) long length = ((Number) ((Literal) val3).getValue())
.longValue(); .longValue();
long endIndex = length + (jpqlStart - 1); long endIndex = length + (jpqlStart - 1);
end = factory.newLiteral(new Long(endIndex), end = factory.newLiteral(Long.valueOf(endIndex),
Literal.TYPE_NUMBER); Literal.TYPE_NUMBER);
} }
} else { } else {
@ -2140,7 +2140,7 @@ public class JPQLExpressionBuilder
private JPQLNode child(JPQLNode node, int childNum, int assertCount) { private JPQLNode child(JPQLNode node, int childNum, int assertCount) {
if (node.children.length != assertCount) if (node.children.length != assertCount)
throw parseException(EX_USER, "wrong-child-count", throw parseException(EX_USER, "wrong-child-count",
new Object[]{ new Integer(assertCount), node, new Object[]{ Integer.valueOf(assertCount), node,
Arrays.asList(node.children) }, null); Arrays.asList(node.children) }, null);
return node.children[childNum]; return node.children[childNum];

View File

@ -1529,7 +1529,7 @@ public class FieldMetaData
return Float.valueOf(val); return Float.valueOf(val);
case JavaTypes.CHAR: case JavaTypes.CHAR:
case JavaTypes.CHAR_OBJ: case JavaTypes.CHAR_OBJ:
return new Character(val.charAt(0)); return Character.valueOf(val.charAt(0));
case JavaTypes.STRING: case JavaTypes.STRING:
return val; return val;
case JavaTypes.ENUM: case JavaTypes.ENUM:

View File

@ -272,20 +272,20 @@ public class JavaTypes {
if (val instanceof Byte) if (val instanceof Byte)
return val; return val;
if (val instanceof Number) if (val instanceof Number)
return new Byte(((Number) val).byteValue()); return Byte.valueOf(((Number) val).byteValue());
// no break // no break
case BYTE: case BYTE:
if (val instanceof String) if (val instanceof String)
return new Byte(val.toString()); return Byte.valueOf((String)val);
return val; return val;
case CHAR: case CHAR:
case CHAR_OBJ: case CHAR_OBJ:
if (val instanceof Character) if (val instanceof Character)
return val; return val;
if (val instanceof String) if (val instanceof String)
return new Character(val.toString().charAt(0)); return Character.valueOf(val.toString().charAt(0));
if (val instanceof Number) if (val instanceof Number)
return new Character((char) ((Number) val).intValue()); return Character.valueOf((char) ((Number) val).intValue());
return val; return val;
case DATE: case DATE:
if (val instanceof String) if (val instanceof String)
@ -319,7 +319,7 @@ public class JavaTypes {
// no break // no break
case INT: case INT:
if (val instanceof String) if (val instanceof String)
return new Integer(val.toString()); return Integer.valueOf(val.toString());
return val; return val;
case LONG_OBJ: case LONG_OBJ:
if (val instanceof Long) if (val instanceof Long)
@ -329,7 +329,7 @@ public class JavaTypes {
// no break // no break
case LONG: case LONG:
if (val instanceof String) if (val instanceof String)
return new Long(val.toString()); return Long.valueOf(val.toString());
return val; return val;
case NUMBER: case NUMBER:
if (val instanceof Number) if (val instanceof Number)
@ -341,11 +341,11 @@ public class JavaTypes {
if (val instanceof Short) if (val instanceof Short)
return val; return val;
if (val instanceof Number) if (val instanceof Number)
return new Short(((Number) val).shortValue()); return Short.valueOf(((Number) val).shortValue());
// no break // no break
case SHORT: case SHORT:
if (val instanceof String) if (val instanceof String)
return new Short(val.toString()); return Short.valueOf(val.toString());
return val; return val;
case STRING: case STRING:
return val.toString(); return val.toString();

View File

@ -596,15 +596,15 @@ public class ApplicationIds {
} }
public void storeByteField(int field, byte val) { public void storeByteField(int field, byte val) {
store(new Byte(val)); store(Byte.valueOf(val));
} }
public void storeCharField(int field, char val) { public void storeCharField(int field, char val) {
store(new Character(val)); store(Character.valueOf(val));
} }
public void storeShortField(int field, short val) { public void storeShortField(int field, short val) {
store(new Short(val)); store(Short.valueOf(val));
} }
public void storeIntField(int field, int val) { public void storeIntField(int field, int val) {

View File

@ -50,7 +50,7 @@ public final class ByteId extends OpenJPAId {
} }
public Object getIdObject() { public Object getIdObject() {
return new Byte(key); return Byte.valueOf(key);
} }
public String toString() { public String toString() {

View File

@ -50,7 +50,7 @@ public final class CharId extends OpenJPAId {
} }
public Object getIdObject() { public Object getIdObject() {
return new Character(key); return Character.valueOf(key);
} }
public String toString() { public String toString() {

View File

@ -116,7 +116,7 @@ public abstract class OpenJPAId
superclass = base.getSuperclass(); superclass = base.getSuperclass();
} }
_typeHash = base.hashCode(); _typeHash = base.hashCode();
_typeCache.put(type, new Integer(_typeHash)); _typeCache.put(type, Integer.valueOf(_typeHash));
} else { } else {
_typeHash = typeHashInt.intValue(); _typeHash = typeHashInt.intValue();
} }

View File

@ -50,7 +50,7 @@ public final class ShortId extends OpenJPAId {
} }
public Object getIdObject() { public Object getIdObject() {
return new Short(key); return Short.valueOf(key);
} }
public String toString() { public String toString() {

View File

@ -121,7 +121,7 @@ public class ParseException
String curtok = curtokBuf.toString(); String curtok = curtokBuf.toString();
return _loc.get("bad-parse", new Object[]{ curtok, return _loc.get("bad-parse", new Object[]{ curtok,
new Integer(currentToken.next.beginColumn), expected }); Integer.valueOf(currentToken.next.beginColumn), expected });
} }
/** /**