poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1568812 - in /poi/trunk/src: ooxml/java/org/apache/poi/ ooxml/testcases/org/apache/poi/ scratchpad/src/org/apache/poi/hwpf/model/ scratchpad/src/org/apache/poi/hwpf/sprm/ scratchpad/src/org/apache/poi/hwpf/usermodel/
Date Sun, 16 Feb 2014 19:35:17 GMT
Author: kiwiwings
Date: Sun Feb 16 19:35:16 2014
New Revision: 1568812

URL: http://svn.apache.org/r1568812
Log:
FindBugs fix
- fixed "equals() method does not check for null argument"
- see http://findbugs.sourceforge.net/bugDescriptions.html#NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java Sun Feb 16 19:35:16 2014
@@ -284,7 +284,7 @@ public class POIXMLDocumentPart {
 
     @Override
     public String toString(){
-        return packagePart == null ? null : packagePart.toString();
+        return packagePart == null ? "" : packagePart.toString();
     }
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java Sun Feb 16 19:35:16
2014
@@ -170,7 +170,7 @@ public final class TestPOIXMLDocument ex
         assertNull(part.getRelationId(null));
         assertFalse(part.removeRelation(null, true));
         part.removeRelation(null);
-        assertNull(part.toString());
+        assertEquals("",part.toString());
         part.onDocumentCreate();
         //part.getTargetPart(null);
     }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java Sun Feb 16 19:35:16 2014
@@ -182,49 +182,20 @@ public final class Ffn
   }
 
   @Override
-  public boolean equals(Object o)
-    {
-    boolean retVal = true;
-
-    if (((Ffn)o).get_cbFfnM1() == _cbFfnM1)
-    {
-      if(((Ffn)o)._info == _info)
-      {
-      if(((Ffn)o)._wWeight == _wWeight)
-      {
-        if(((Ffn)o)._chs == _chs)
-        {
-        if(((Ffn)o)._ixchSzAlt == _ixchSzAlt)
-        {
-          if(Arrays.equals(((Ffn)o)._panose,_panose))
-          {
-          if(Arrays.equals(((Ffn)o)._fontSig,_fontSig))
-          {
-                  if(!(Arrays.equals(((Ffn)o)._xszFfn,_xszFfn)))
-                    retVal = false;
-          }
-          else
-            retVal = false;
-          }
-          else
-          retVal = false;
-        }
-        else
-          retVal = false;
-        }
-        else
-        retVal = false;
-      }
-      else
-        retVal = false;
-      }
-      else
-      retVal = false;
-    }
-    else
-      retVal = false;
-
-    return retVal;
+  public boolean equals(Object other) {
+      if (!(other instanceof Ffn)) return false;
+      Ffn o = (Ffn)other;
+      
+      return (
+             o._cbFfnM1 == this._cbFfnM1
+          && o._info == this._info
+          && o._wWeight == _wWeight
+          && o._chs == _chs
+          && o._ixchSzAlt == _ixchSzAlt
+          && Arrays.equals(o._panose,_panose)
+          && Arrays.equals(o._fontSig,_fontSig)
+          && Arrays.equals(o._xszFfn,_xszFfn)
+      );
   }
 
 

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java Sun Feb 16 19:35:16
2014
@@ -138,29 +138,20 @@ public final class FontTable
   }
 
   @Override
-  public boolean equals(Object o)
-  {
-  	boolean retVal = true;
-
-    if(((FontTable)o).getStringCount() == _stringCount)
-    {
-      if(((FontTable)o).getExtraDataSz() == _extraDataSz)
-      {
-        Ffn[] fontNamesNew = ((FontTable)o).getFontNames();
-        for(int i = 0;i<_stringCount; i++)
-        {
-          if(!(_fontNames[i].equals(fontNamesNew[i])))
-            retVal = false;
-        }
+  public boolean equals(Object other) {
+      if (!(other instanceof FontTable)) return false;
+      FontTable o = (FontTable)other;
+
+      if (o._stringCount != this._stringCount
+          || o._extraDataSz != this._extraDataSz
+          || o._fontNames.length != this._fontNames.length
+      ) return false;
+      
+      for (int i=0; i<o._fontNames.length; i++) {
+          if (!o._fontNames[i].equals(this._fontNames[i])) return false;
       }
-      else
-        retVal = false;
-    }
-    else
-	    retVal = false;
-
-
-	  return retVal;
+      
+      return true;
   }
 
   @Override

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ParagraphHeight.java Sun Feb 16
19:35:16 2014
@@ -76,6 +76,7 @@ public final class ParagraphHeight
 
   public boolean equals(Object o)
   {
+    if (!(o instanceof ParagraphHeight)) return false;
     ParagraphHeight ph = (ParagraphHeight)o;
 
     return infoField == ph.infoField && reserved == ph.reserved &&

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java Sun Feb 16 19:35:16
2014
@@ -163,6 +163,8 @@ public abstract class PropertyNode<T ext
 
   public boolean equals(Object o)
   {
+    if (!(o instanceof PropertyNode)) return false;
+
     if (limitsAreEqual(o))
     {
       Object testBuf = ((PropertyNode<?>)o)._buf;

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/SectionDescriptor.java Sun Feb
16 19:35:16 2014
@@ -80,6 +80,7 @@ public final class SectionDescriptor
   @Override
   public boolean equals(Object o)
   {
+    if (!(o instanceof SectionDescriptor)) return false;
     SectionDescriptor sed = (SectionDescriptor)o;
     return sed.fn == fn && sed.fnMpr == fnMpr;
   }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java Sun Feb 16 19:35:16
2014
@@ -178,28 +178,22 @@ public final class StyleSheet implements
   @Override
   public boolean equals(Object o)
   {
+    if (!(o instanceof StyleSheet)) return false;
     StyleSheet ss = (StyleSheet)o;
 
-    if (ss._stshif.equals( this._stshif ) && ss._cbStshi == _cbStshi)
-    {
-      if (ss._styleDescriptions.length == _styleDescriptions.length)
-      {
-        for (int x = 0; x < _styleDescriptions.length; x++)
-        {
-          // check for null
-          if (ss._styleDescriptions[x] != _styleDescriptions[x])
-          {
-            // check for equality
-            if (!ss._styleDescriptions[x].equals(_styleDescriptions[x]))
-            {
-              return false;
-            }
-          }
-        }
-        return true;
-      }
+    if (!ss._stshif.equals( this._stshif )
+        || ss._cbStshi != this._cbStshi
+        || ss._styleDescriptions.length != this._styleDescriptions.length
+    ) return false;
+    
+    for (int i=0; i<_styleDescriptions.length; i++) {
+        StyleDescription tsd = this._styleDescriptions[i];
+        StyleDescription osd = ss._styleDescriptions[i];
+        if (tsd == null && osd == null) continue;
+        if (tsd == null || osd == null || !osd.equals(tsd)) return false;
     }
-    return false;
+
+    return true;
   }
 
   @Override

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java Sun Feb 16 19:35:16
2014
@@ -204,13 +204,16 @@ public class TextPiece extends PropertyN
    @Override
    public boolean equals(Object o)
    {
-     if (limitsAreEqual(o))
-     {
-       TextPiece tp = (TextPiece)o;
-       return getStringBuilder().toString().equals(tp.getStringBuilder().toString()) &&
-              tp._usesUnicode == _usesUnicode && _pd.equals(tp._pd);
-     }
-     return false;
+     if (!(o instanceof TextPiece)) return false;
+     TextPiece tp = (TextPiece)o;
+     assert(_buf != null && tp._buf != null && _pd != null && tp._pd
!= null);
+     
+     return (
+            limitsAreEqual(o)
+         && tp._usesUnicode == this._usesUnicode
+         && tp._buf.toString().equals(this._buf.toString())
+         && tp._pd.equals(this._pd)
+     );
    }
 
    @Override

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java Sun Feb 16
19:35:16 2014
@@ -160,6 +160,7 @@ public class TextPieceTable implements C
 
     public boolean equals( Object o )
     {
+        if (!(o instanceof TextPieceTable)) return false;
         TextPieceTable tpt = (TextPieceTable) o;
 
         int size = tpt._textPieces.size();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/UPX.java Sun Feb 16 19:35:16 2014
@@ -43,6 +43,7 @@ public final class UPX
   @Override
   public boolean equals(Object o)
   {
+    if (!(o instanceof UPX)) return false;
     UPX upx = (UPX)o;
     return Arrays.equals(_upx, upx._upx);
   }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java Sun Feb 16 19:35:16
2014
@@ -154,6 +154,7 @@ public final class SprmBuffer implements
   @Override
   public boolean equals(Object obj)
   {
+    if (!(obj instanceof SprmBuffer)) return false;
     SprmBuffer sprmBuf = (SprmBuffer)obj;
     return (Arrays.equals(_buf, sprmBuf._buf));
   }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java Sun Feb 16
19:35:16 2014
@@ -71,6 +71,7 @@ public final class BorderCode implements
   @Override
   public boolean equals(Object o)
   {
+    if (!(o instanceof BorderCode)) return false;
     BorderCode brc = (BorderCode)o;
     return _info == brc._info && _info2 == brc._info2;
   }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DateAndTime.java Sun Feb 16
19:35:16 2014
@@ -75,6 +75,7 @@ public final class DateAndTime
   @Override
   public boolean equals(Object o)
   {
+    if (!(o instanceof DateAndTime)) return false;
     DateAndTime dttm = (DateAndTime)o;
     return _info == dttm._info && _info2 == dttm._info2;
   }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java?rev=1568812&r1=1568811&r2=1568812&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/LineSpacingDescriptor.java
Sun Feb 16 19:35:16 2014
@@ -75,6 +75,7 @@ public final class LineSpacingDescriptor
   @Override
   public boolean equals(Object o)
   {
+    if (!(o instanceof LineSpacingDescriptor)) return false;
     LineSpacingDescriptor lspd = (LineSpacingDescriptor)o;
 
     return _dyaLine == lspd._dyaLine && _fMultiLinespace == lspd._fMultiLinespace;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message