You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/12/31 01:54:25 UTC
svn commit: r491358 - in
/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap:
schema/ schema/syntax/ util/
Author: akarasulu
Date: Sat Dec 30 16:54:24 2006
New Revision: 491358
URL: http://svn.apache.org/viewvc?view=rev&rev=491358
Log:
commiting on behalf of elecharny: Fixed potential NPE. Modified some static fields to private in StringTools. Added some accessor methods. Basically, cleaned some code to avoid NPE and potential errors
Modified:
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectIdentifierComparator.java
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/ArrayUtils.java
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/BooleanUtils.java
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java?view=diff&rev=491358&r1=491357&r2=491358
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ByteArrayComparator.java Sat Dec 30 16:54:24 2006
@@ -45,17 +45,17 @@
// Handle some basis cases
// -------------------------------------------------------------------
- if ( b1 == null && b2 == null )
+ if ( ( b1 == null ) && ( b2 == null ) )
{
return 0;
}
- if ( b1 != null && b2 == null )
+ if ( ( b1 != null ) && ( b2 == null ) )
{
return 1;
}
- if ( b1 == null && b2 != null )
+ if ( ( b1 == null ) && ( b2 != null ) )
{
return -1;
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectIdentifierComparator.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectIdentifierComparator.java?view=diff&rev=491358&r1=491357&r2=491358
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectIdentifierComparator.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectIdentifierComparator.java Sat Dec 30 16:54:24 2006
@@ -37,15 +37,15 @@
public int compare( Object o1, Object o2 )
{
- if ( o1 == null && o2 == null )
+ if ( ( o1 == null ) && ( o2 == null ) )
{
return 0;
}
- else if ( o1 != null && o2 == null )
+ else if ( ( o1 != null ) && ( o2 == null ) )
{
return 1;
}
- else if ( o1 == null && o2 != null )
+ else if ( ( o1 == null ) && ( o2 != null ) )
{
return -1;
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java?view=diff&rev=491358&r1=491357&r2=491358
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/PrepareString.java Sat Dec 30 16:54:24 2006
@@ -4590,7 +4590,11 @@
public static StringBuilder bidi( char[] array )
{
StringBuilder sb = new StringBuilder( array == null ? 0 : array.length );
- sb.append( array );
+
+ if ( array != null )
+ {
+ sb.append( array );
+ }
return sb;
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java?view=diff&rev=491358&r1=491357&r2=491358
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java Sat Dec 30 16:54:24 2006
@@ -54,7 +54,7 @@
private List<Pattern> compiledREs;
/** The default pattern used to check a TelephoneNumber */
- private final String DEFAULT_REGEXP = "^ *[+]? *((\\([0-9- ]+\\))|[0-9- ]+)+$";
+ private final static String DEFAULT_REGEXP = "^ *[+]? *((\\([0-9- ]+\\))|[0-9- ]+)+$";
/** The compiled default pattern */
private Pattern defaultPattern = Pattern.compile( DEFAULT_REGEXP );
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/ArrayUtils.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/ArrayUtils.java?view=diff&rev=491358&r1=491357&r2=491358
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/ArrayUtils.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/ArrayUtils.java Sat Dec 30 16:54:24 2006
@@ -3774,7 +3774,7 @@
final Double[] result = new Double[array.length];
for ( int i = 0; i < array.length; i++ )
{
- result[i] = new Double( array[i] );
+ result[i] = Double.valueOf( array[i] );
}
return result;
}
@@ -3881,7 +3881,7 @@
final Float[] result = new Float[array.length];
for ( int i = 0; i < array.length; i++ )
{
- result[i] = new Float( array[i] );
+ result[i] = Float.valueOf( array[i] );
}
return result;
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/BooleanUtils.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/BooleanUtils.java?view=diff&rev=491358&r1=491357&r2=491358
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/BooleanUtils.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/BooleanUtils.java Sat Dec 30 16:54:24 2006
@@ -782,7 +782,7 @@
// Similar performance for null, 'false', and other strings not length
// 2/3/4.
// 'true'/'TRUE' match 4 times slower, 'tRUE'/'True' 7 times slower.
- if ( str == "true" )
+ if ( "true".equals( str ) )
{
return true;
}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?view=diff&rev=491358&r1=491357&r2=491358
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java Sat Dec 30 16:54:24 2006
@@ -256,9 +256,9 @@
}
else
{
- byte c = byteArray[index++];
+ byte b = byteArray[index++];
- if ( ( c > 127 ) || ( StringTools.ALPHA[c] == false ) )
+ if ( StringTools.isAlpha( b ) == false )
{
return -1;
}
@@ -290,7 +290,7 @@
{
char c = charArray[index++];
- if ( ( c > 127 ) || ( StringTools.ALPHA[c] == false ) )
+ if ( StringTools.isAlpha( c ) == false )
{
return PARSING_ERROR;
}
@@ -393,9 +393,14 @@
*/
public static int isPairChar( String string, int index )
{
+ if ( string == null )
+ {
+ return PARSING_ERROR;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return PARSING_ERROR;
}
@@ -501,9 +506,14 @@
*/
public static int isStringChar( String string, int index )
{
+ if ( string == null )
+ {
+ return PARSING_ERROR;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return PARSING_ERROR;
}
@@ -595,9 +605,14 @@
*/
public static int isQuoteChar( String string, int index )
{
+ if ( string == null )
+ {
+ return PARSING_ERROR;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return PARSING_ERROR;
}
@@ -717,8 +732,7 @@
*/
private static byte getHexPair( String string, int index )
{
- return (byte)((StringTools.HEX_VALUE[string.charAt( index )] << 4) |
- (StringTools.HEX_VALUE[string.charAt( index + 1 )]) );
+ return StringTools.getHexValue( string.charAt( index ), string.charAt( index + 1 ) );
}
/**
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?view=diff&rev=491358&r1=491357&r2=491358
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Sat Dec 30 16:54:24 2006
@@ -82,7 +82,7 @@
private static final int UTF8_SIX_BYTES = 0x00FC;
/** <alpha> ::= [0x41-0x5A] | [0x61-0x7A] */
- public static final boolean[] ALPHA =
+ private static final boolean[] ALPHA =
{
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
@@ -103,7 +103,7 @@
};
/** <alpha-lower-case> ::= [0x61-0x7A] */
- public static final boolean[] ALPHA_LOWER_CASE =
+ private static final boolean[] ALPHA_LOWER_CASE =
{
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
@@ -124,7 +124,7 @@
};
/** <alpha-upper-case> ::= [0x41-0x5A] */
- public static final boolean[] ALPHA_UPPER_CASE =
+ private static final boolean[] ALPHA_UPPER_CASE =
{
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
@@ -145,7 +145,7 @@
};
/** <alpha-digit> | <digit> */
- public static final boolean[] ALPHA_DIGIT =
+ private static final boolean[] ALPHA_DIGIT =
{
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
@@ -166,7 +166,7 @@
};
/** <alpha> | <digit> | '-' */
- public static final boolean[] CHAR =
+ private static final boolean[] CHAR =
{
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
@@ -187,7 +187,7 @@
};
/** '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' */
- public static final boolean[] DIGIT =
+ private static final boolean[] DIGIT =
{
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,
@@ -250,7 +250,7 @@
/** <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66] */
- public static final byte[] HEX_VALUE =
+ private static final byte[] HEX_VALUE =
{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00 -> 0F
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10 -> 1F
@@ -262,7 +262,7 @@
};
/** lowerCase = 'a' .. 'z', '0'..'9', '-' */
- public static final char[] LOWER_CASE =
+ private static final char[] LOWER_CASE =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
@@ -291,7 +291,7 @@
};
/** upperCase = 'A' .. 'Z', '0'..'9', '-' */
- public static final char[] UPPER_CASE =
+ private static final char[] UPPER_CASE =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
@@ -318,6 +318,7 @@
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
+
private static final int CHAR_ONE_BYTE_MASK = 0xFFFFFF80;
private static final int CHAR_TWO_BYTES_MASK = 0xFFFFF800;
@@ -846,7 +847,6 @@
*/
public static final List getPaths( String paths, FileFilter filter )
{
- final int max = paths.length() - 1;
int start = 0;
int stop = -1;
String path = null;
@@ -858,6 +858,8 @@
return list;
}
+ final int max = paths.length() - 1;
+
// Loop spliting string using OS path separator: terminate
// when the start index is at the end of the paths string.
while ( start < max )
@@ -1483,12 +1485,16 @@
*/
public static final boolean areEquals( String string1, int index, String text )
{
+ if ( ( string1 == null ) || ( text == null ) )
+ {
+ return false;
+ }
+
int length1 = string1.length();
int length2 = text.length();
- if ( ( string1 == null ) || ( length1 == 0 ) || ( length1 <= index ) || ( index < 0 )
- || ( text == null ) || ( length2 == 0 )
- || ( length2 > ( length1 + index ) ) )
+ if ( ( length1 == 0 ) || ( length1 <= index ) || ( index < 0 )
+ || ( length2 == 0 ) || ( length2 > ( length1 + index ) ) )
{
return false;
}
@@ -1625,9 +1631,14 @@
*/
public static final boolean isBit( String string, int index )
{
+ if ( string == null )
+ {
+ return false;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return false;
}
@@ -1650,9 +1661,14 @@
*/
public static final char charAt( String string, int index )
{
+ if ( string == null )
+ {
+ return '\0';
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return '\0';
}
@@ -1662,6 +1678,25 @@
}
}
+ public static byte getHexValue( char c1, char c2 )
+ {
+ if ( ( c1 > 127 ) || (c2 > 127 ) || ( c1 < 0 ) | ( c2 < 0 ) )
+ {
+ return -1;
+ }
+
+ return (byte)( ( HEX_VALUE[c1] << 4 ) | HEX_VALUE[c2] );
+ }
+
+ public static byte getHexValue( char c )
+ {
+ if ( ( c > 127 ) || ( c < 0 ) )
+ {
+ return -1;
+ }
+
+ return HEX_VALUE[c];
+ }
/**
* Check if the current character is an Hex Char <hex> ::= [0x30-0x39] |
@@ -1793,6 +1828,34 @@
return ( car >= '0' ) && ( car <= '9' );
}
+ /**
+ * Test if the current byte is an Alpha character :
+ * <alpha> ::= [0x41-0x5A] | [0x61-0x7A]
+ *
+ * @param c The byte to test
+ *
+ * @return <code>true</code> if the byte is an Alpha
+ * character
+ */
+ public static final boolean isAlpha( byte c )
+ {
+ return ( ( c > 127 ) || ( ALPHA[c] == false ) );
+ }
+
+ /**
+ * Test if the current character is an Alpha character :
+ * <alpha> ::= [0x41-0x5A] | [0x61-0x7A]
+ *
+ * @param c The char to test
+ *
+ * @return <code>true</code> if the character is an Alpha
+ * character
+ */
+ public static final boolean isAlpha( char c )
+ {
+ return ( ( c > 127 ) || ( ALPHA[c] == false ) );
+ }
+
/**
* Test if the current character is an Alpha character : <alpha> ::=
@@ -1872,9 +1935,14 @@
*/
public static final boolean isAlphaASCII( String string, int index )
{
+ if ( string == null )
+ {
+ return false;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return false;
}
@@ -1906,9 +1974,14 @@
*/
public static final boolean isAlphaLowercaseASCII( String string, int index )
{
+ if ( string == null )
+ {
+ return false;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return false;
}
@@ -1940,9 +2013,14 @@
*/
public static final boolean isAlphaUppercaseASCII( String string, int index )
{
+ if ( string == null )
+ {
+ return false;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return false;
}
@@ -2019,9 +2097,14 @@
*/
public static final boolean isDigit( String string, int index )
{
+ if ( string == null )
+ {
+ return false;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return false;
}
@@ -2065,9 +2148,14 @@
*/
public static final boolean isAlphaDigit( String string, int index )
{
+ if ( string == null )
+ {
+ return false;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return false;
}
@@ -2163,9 +2251,14 @@
*/
public static final boolean isAlphaDigitMinus( String string, int index )
{
+ if ( string == null )
+ {
+ return false;
+ }
+
int length = string.length();
- if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
{
return false;
}
@@ -2690,6 +2783,7 @@
{
return null;
}
+
return str.toUpperCase();
}
@@ -2718,6 +2812,7 @@
{
return null;
}
+
return str.toLowerCase();
}
@@ -2979,7 +3074,7 @@
*/
public static final String getDefaultCharsetName()
{
- if (null == defaultCharset)
+ if ( null == defaultCharset )
{
try
{
@@ -3012,6 +3107,7 @@
}
char[] chars = str.toCharArray();
+
if ( chars[0] != '#' )
{
throw new InvalidNameException( "Expected string to start with a '#' character. " +
@@ -3043,11 +3139,18 @@
*/
public static final String decodeEscapedHex( String str ) throws InvalidNameException
{
+ if ( str == null )
+ {
+ throw new InvalidNameException( "Expected string to be non-null " +
+ "with valid index." );
+ }
+
int length = str.length();
- if ( str == null || length == 0 )
+
+ if ( length == 0 )
{
- throw new InvalidNameException( "Expected string to be non-empty or non-null " +
- "with valid index." );
+ throw new InvalidNameException( "Expected string to be non-empty " +
+ "with valid index." );
}
// create buffer and add everything before start of scan
@@ -3085,6 +3188,7 @@
private static int collectEscapedHexBytes( ByteBuffer bb, String str, int index )
{
int advanceBy = 0;
+
for ( int ii = index; ii < str.length(); ii += 3, advanceBy += 3 )
{
// we have the start of a hex escape sequence