directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r491433 - in /directory/trunks/shared/asn1/src: main/java/org/apache/directory/shared/asn1/ main/java/org/apache/directory/shared/asn1/ber/ main/java/org/apache/directory/shared/asn1/ber/tlv/ main/java/org/apache/directory/shared/asn1/der/ ...
Date Sun, 31 Dec 2006 15:37:38 GMT
Author: elecharny
Date: Sun Dec 31 07:37:38 2006
New Revision: 491433

URL: http://svn.apache.org/viewvc?view=rev&rev=491433
Log:
Cleaned the code, after having used FindBugs to check it. Many little errors has been fixed.
Tests has been added

Modified:
    directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java
    directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java
    directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java
    directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
    directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/der/DERTaggedObject.java
    directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java
    directory/trunks/shared/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java

Modified: directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java?view=diff&rev=491433&r1=491432&r2=491433
==============================================================================
--- directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java
(original)
+++ directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/AbstractAsn1Object.java
Sun Dec 31 07:37:38 2006
@@ -37,13 +37,13 @@
     // ----------------------------------------------------------------------------
 
     /** The object's current length. It is used while decoding PDUs */
-    private transient int currentLength;
+    private int currentLength;
 
     /** The object's expected length. It is used while decoding PDUs */
-    private transient int expectedLength;
+    private int expectedLength;
 
     /** The encapsulating Object */
-    protected transient AbstractAsn1Object parent;
+    protected AbstractAsn1Object parent;
 
 
     // ~ Methods

Modified: directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java?view=diff&rev=491433&r1=491432&r2=491433
==============================================================================
--- directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java
(original)
+++ directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/Asn1Decoder.java
Sun Dec 31 07:37:38 2006
@@ -121,15 +121,8 @@
 
             if ( IS_DEBUG )
             {
-                if ( tlv != null )
-                {
-                    byte tag = container.getCurrentTLV().getTag();
-                    log.debug( "Tag {} has been decoded", Asn1StringUtils.dumpByte( tag )
);
-                }
-                else
-                {
-                    log.debug( "Tag has been decoded, but is null" );
-                }
+                byte tag = container.getCurrentTLV().getTag();
+                log.debug( "Tag {} has been decoded", Asn1StringUtils.dumpByte( tag ) );
             }
 
             return MORE;
@@ -391,7 +384,7 @@
             {
                 if  ( tlv != null )
                 {
-                    log.debug( "Root TLV[{}]", new Integer( length ) );
+                    log.debug( "Root TLV[{}]", Integer.valueOf( length ) );
                 }
                 else
                 {
@@ -410,7 +403,7 @@
             {
                 // The expected length is lower than the Value length of the
                 // current TLV. This is an error...
-                log.error( "tlv[{}, {}]", new Integer( expectedLength ), new Integer( currentLength
) );
+                log.error( "tlv[{}, {}]", Integer.valueOf( expectedLength ), Integer.valueOf(
currentLength ) );
                 throw new DecoderException( "The current Value length is above the expected
length" );
             }
 
@@ -503,7 +496,7 @@
 
         if ( IS_DEBUG )
         {
-            log.debug( "Length {} has been decoded", new Integer( length ) );
+            log.debug( "Length {} has been decoded", Integer.valueOf( length ) );
         }
 
         if ( length == 0 )

Modified: directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java?view=diff&rev=491433&r1=491432&r2=491433
==============================================================================
--- directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java
(original)
+++ directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java
Sun Dec 31 07:37:38 2006
@@ -46,7 +46,7 @@
     private int lengthNbBytes;
     
     /** The number of length's bytes currently read */
-    private int LengthBytesRead;
+    private int lengthBytesRead;
 
     /** The current Value being processed */
     private Value value;
@@ -77,13 +77,13 @@
     public static final int SHORT_MASK = 0x1F;
 
     /** A mask to get the Length form */
-    public static final transient int LENGTH_LONG_FORM = 0x0080;
+    public static final int LENGTH_LONG_FORM = 0x0080;
 
     /** Value of the reserved extension */
-    public static final transient int LENGTH_EXTENSION_RESERVED = 0x7F;
+    public static final int LENGTH_EXTENSION_RESERVED = 0x7F;
 
     /** A mask to get the long form value */
-    public static final transient int LENGTH_SHORT_MASK = 0x007F;
+    public static final int LENGTH_SHORT_MASK = 0x007F;
     
     /** A speedup for single bytes length */
     static byte[][] ONE_BYTE = new byte[256][];
@@ -394,18 +394,18 @@
 
     public int getLengthBytesRead()
     {
-        return LengthBytesRead;
+        return lengthBytesRead;
     }
 
 
     public void setLengthBytesRead( int lengthBytesRead )
     {
-        LengthBytesRead = lengthBytesRead;
+        this.lengthBytesRead = lengthBytesRead;
     }
     
     public void incLengthBytesRead()
     {
-        LengthBytesRead++;
+        lengthBytesRead++;
     }
 }
  

Modified: directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java?view=diff&rev=491433&r1=491432&r2=491433
==============================================================================
--- directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
(original)
+++ directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/ber/tlv/Value.java
Sun Dec 31 07:37:38 2006
@@ -84,7 +84,9 @@
      */
     public Value(byte[] value)
     {
-        data = value;
+        // Do a copy of the byte array
+        data = new byte[value.length];
+        System.arraycopy( value, 0, data, 0, value.length );
         currentPos = 0;
     }
 

Modified: directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/der/DERTaggedObject.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/der/DERTaggedObject.java?view=diff&rev=491433&r1=491432&r2=491433
==============================================================================
--- directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/der/DERTaggedObject.java
(original)
+++ directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/der/DERTaggedObject.java
Sun Dec 31 07:37:38 2006
@@ -85,7 +85,10 @@
         this.explicit = explicit;
         this.tag = tag;
         this.obj = obj;
-        this.bytes = bytes;
+
+        // Copy the byte array
+        this.bytes = new byte[bytes.length];
+        System.arraycopy( bytes, 0, this.bytes, 0, bytes.length );
     }
 
 

Modified: directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java?view=diff&rev=491433&r1=491432&r2=491433
==============================================================================
--- directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java
(original)
+++ directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/primitives/OID.java
Sun Dec 31 07:37:38 2006
@@ -23,6 +23,7 @@
 import java.io.Serializable;
 
 import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.util.Asn1StringUtils;
 
 
 /**
@@ -119,7 +120,7 @@
 
         if ( oid.length < 1 )
         {
-            throw new DecoderException( "Invalid OID : " + oid );
+            throw new DecoderException( "Invalid OID : " + Asn1StringUtils.dumpBytes( oid
) );
         }
 
         // First, we have to calculate the number of int to allocate

Modified: directory/trunks/shared/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java?view=diff&rev=491433&r1=491432&r2=491433
==============================================================================
--- directory/trunks/shared/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
(original)
+++ directory/trunks/shared/asn1/src/test/java/org/apache/directory/shared/asn1/ber/tlv/ValueTest.java
Sun Dec 31 07:37:38 2006
@@ -268,4 +268,18 @@
             Assert.assertEquals( testedInt[i], value );
         }
     }
+    
+    public void testNewByteArrayValue()
+    {
+        byte[] bb = new byte[]{0x01, (byte)0xFF};
+        
+        Value v = new Value( bb );
+        byte[] vv = v.getData();
+        
+        assertEquals( 0x01, vv[0] );
+        assertEquals( (byte)0xFF, vv[1] );
+        
+        bb[0] = 0x00;
+        assertEquals( 0x01, vv[0] );
+    }
 }



Mime
View raw message