[cp-patches] Patch: convert new Boolean(X) to Boolean.valueOf(X)

2005-09-14 Thread Anthony Green
While messing around with FindBugs, I came up with the following useful
patch.  It converts all new Boolean(X) instances to
Boolean.valueOf(X).  Ok?

AG
h

2005-09-13  Anthony Green  [EMAIL PROTECTED]

	* javax/swing/plaf/basic/BasicFileChooserUI.java,
	javax/swing/filechooser/FileSystemView.java,
	java/util/logging/LogManager.java,
	gnu/xml/libxmlj/dom/GnomeDocument.java,
	gnu/xml/aelfred2/JAXPFactory.java,
	gnu/java/security/x509/ext/Extension.java,
	gnu/java/security/x509/ext/BasicConstraints.java,
	gnu/java/rmi/server/RMIObjectInputStream.java,
	gnu/java/rmi/dgc/DGCImpl_Stub.java,
	gnu/java/beans/decoder/BooleanHandler.java: Use
	Boolean.valueOf() instead of new Boolean.


Index: gnu/java/beans/decoder/BooleanHandler.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/beans/decoder/BooleanHandler.java,v
retrieving revision 1.2
diff -u -p -r1.2 BooleanHandler.java
--- gnu/java/beans/decoder/BooleanHandler.java	2 Jul 2005 20:32:12 -	1.2
+++ gnu/java/beans/decoder/BooleanHandler.java	14 Sep 2005 07:00:11 -
@@ -57,10 +57,10 @@ class BooleanHandler extends SimpleHandl
   protected Object parse(String number) throws AssemblyException
   {
 if (number.equals(true))
-  return new Boolean(true);
+  return Boolean.valueOf(true);
 
 if (number.equals(false))
-  return new Boolean(false);
+  return Boolean.valueOf(false);
 
 throw new AssemblyException(new IllegalArgumentException(Element contained no valid boolean value.));
   }
Index: gnu/java/rmi/dgc/DGCImpl_Stub.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/rmi/dgc/DGCImpl_Stub.java,v
retrieving revision 1.3
diff -u -p -r1.3 DGCImpl_Stub.java
--- gnu/java/rmi/dgc/DGCImpl_Stub.java	2 Jul 2005 20:32:14 -	1.3
+++ gnu/java/rmi/dgc/DGCImpl_Stub.java	14 Sep 2005 07:00:12 -
@@ -81,7 +81,7 @@ public final class DGCImpl_Stub
 public void clean(java.rmi.server.ObjID[] $param_0, long $param_1, java.rmi.dgc.VMID $param_2, boolean $param_3) throws java.rmi.RemoteException {
 try {
 if (useNewInvoke) {
-ref.invoke(this, $method_clean_0, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2, new java.lang.Boolean($param_3)}, -5803803475088455571L);
+ref.invoke(this, $method_clean_0, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2, Boolean.valueOf($param_3)}, -5803803475088455571L);
 }
 else {
 java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 0, interfaceHash);
Index: gnu/java/rmi/server/RMIObjectInputStream.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/rmi/server/RMIObjectInputStream.java,v
retrieving revision 1.8
diff -u -p -r1.8 RMIObjectInputStream.java
--- gnu/java/rmi/server/RMIObjectInputStream.java	2 Jul 2005 20:32:14 -	1.8
+++ gnu/java/rmi/server/RMIObjectInputStream.java	14 Sep 2005 07:00:12 -
@@ -102,7 +102,7 @@ protected Class resolveProxyClass(String
 protected Object readValue(Class valueClass) throws IOException, ClassNotFoundException {
 if(valueClass.isPrimitive()){
 if(valueClass == Boolean.TYPE)
-return new Boolean(readBoolean());
+return Boolean.valueOf(readBoolean());
 if(valueClass == Byte.TYPE)
 return new Byte(readByte());
 if(valueClass == Character.TYPE)
Index: gnu/java/security/x509/ext/BasicConstraints.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/security/x509/ext/BasicConstraints.java,v
retrieving revision 1.3
diff -u -p -r1.3 BasicConstraints.java
--- gnu/java/security/x509/ext/BasicConstraints.java	2 Jul 2005 20:32:14 -	1.3
+++ gnu/java/security/x509/ext/BasicConstraints.java	14 Sep 2005 07:00:13 -
@@ -112,7 +112,7 @@ public class BasicConstraints extends Ex
 if (encoded == null)
   {
 List bc = new ArrayList (2);
-bc.add (new DERValue (DER.BOOLEAN, new Boolean (ca)));
+bc.add (new DERValue (DER.BOOLEAN, Boolean.valueOf (ca)));
 if (pathLenConstraint = 0)
   bc.add (new DERValue (DER.INTEGER,
 BigInteger.valueOf ((long) pathLenConstraint)));
Index: gnu/java/security/x509/ext/Extension.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/security/x509/ext/Extension.java,v
retrieving revision 1.3
diff -u -p -r1.3 Extension.java
--- gnu/java/security/x509/ext/Extension.java	2 Jul 2005 20:32:14 -	1.3
+++ gnu/java/security/x509/ext/Extension.java	14 Sep 2005 07:00:13 -
@@ -232,7 +232,7 @@ public class Extension
   {
 List ext = new ArrayList (3);
 ext.add (new DERValue (DER.OBJECT_IDENTIFIER, 

Re: [cp-patches] Patch: convert new Boolean(X) to Boolean.valueOf(X)

2005-09-14 Thread Mark Wielaard
On Wed, 2005-09-14 at 00:14 -0700, Anthony Green wrote:
 While messing around with FindBugs, I came up with the following useful
 patch.  It converts all new Boolean(X) instances to
 Boolean.valueOf(X).  Ok?
 [...]
 -  return new Boolean(true);
 +  return Boolean.valueOf(true);

OK, but if you know the actual value then using Boolean.TRUE and
Boolean.FALSE seems more appropriate then valueOf(). Could you make that
change?

Thanks,

Mark


signature.asc
Description: This is a digitally signed message part
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] Patch: convert new Boolean(X) to Boolean.valueOf(X)

2005-09-14 Thread David Daney

Archie Cobbs wrote:

Mark Wielaard wrote:


While messing around with FindBugs, I came up with the following useful
patch.  It converts all new Boolean(X) instances to
Boolean.valueOf(X).  Ok?
[...]
-  return new Boolean(true);
+  return Boolean.valueOf(true);



OK, but if you know the actual value then using Boolean.TRUE and
Boolean.FALSE seems more appropriate then valueOf(). Could you make that
change?



That shouldn't be necessary .. the method inliner will
likely take care of that (Boolean.valueOf() is guaranteed
to return either Boolean.TRUE or Boolean.FALSE) so the
ultimate effect should be the same.



None of this is necessary.  But we do it anyway to make the code better.

For me Boolean.TRUE reads much more cleanly than Boolean.valueOf(true). 
 I think it improbable that it is less efficient either.


David Daney


___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] Patch: convert new Boolean(X) to Boolean.valueOf(X)

2005-09-14 Thread Archie Cobbs

David Daney wrote:

Archie Cobbs wrote:

Mark Wielaard wrote:

While messing around with FindBugs, I came up with the following useful
patch.  It converts all new Boolean(X) instances to
Boolean.valueOf(X).  Ok?
[...]
-  return new Boolean(true);
+  return Boolean.valueOf(true);


OK, but if you know the actual value then using Boolean.TRUE and
Boolean.FALSE seems more appropriate then valueOf(). Could you make that
change?


That shouldn't be necessary .. the method inliner will
likely take care of that (Boolean.valueOf() is guaranteed
to return either Boolean.TRUE or Boolean.FALSE) so the
ultimate effect should be the same.


None of this is necessary.  But we do it anyway to make the code better.

For me Boolean.TRUE reads much more cleanly than Boolean.valueOf(true). 
 I think it improbable that it is less efficient either.


Apologies, I didn't see that you were referring to the specific
patch chunk that used the literal constant true.. I completely
agree with you in that case!

All I meant to say is that Boolean.valueOf(x) is not worse than
x ? Boolean.TRUE : Boolean.FALSE.

-Archie

__
Archie Cobbs  *CTO, Awarix*  http://www.awarix.com


___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches