History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CACHE-288
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Lars Torunski
Reporter: Lars Torunski
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OSCache

Error in the HashDiskPersistenceListener byteArrayToHexString

Created: 08/Mar/07 12:48 AM   Updated: 24/Mar/07 06:17 AM
Component/s: Persistence
Affects Version/s: None
Fix Version/s: 2.4


 Description  « Hide
Taken from the forum: http://forums.opensymphony.com/thread.jspa?threadID=68960&messageID=129971#129971

I found a error for the com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener class, in this class have a method named byteArrayToHexString(byte[] in),the old source code follow as:
/**
* Nibble conversion. Thanks to our friends at:
* http://www.devx.com/tips/Tip/13540
* @param in the byte array to convert
* @return a java.lang.String based version of they byte array
*/
static String byteArrayToHexString(byte[] in) {
if ((in == null) || (in.length <= 0)) {
return null;
}

StringBuffer out = new StringBuffer(in.length * 2);

for (int i = 0; i < in.length; i++) {
byte ch = (byte) (in & 0xF0); // Strip off high nibble
ch = (byte) (ch >>> 4);

// shift the bits down
ch = (byte) (ch & 0x0F);

// must do this is high order bit is on!
out.append(PSEUDO[(int) ch]); // convert the nibble to a String Character
ch = (byte) (in & 0x0F); // Strip off low nibble
out.append(PSEUDO[(int) ch]); // convert the nibble to a String Character
i++;
}

return out.toString();
}
notice the bold font, in this part , the code plus once , and int the for (int i = 0; i < in.length; i++) do this plus again, so this method do plus handle twice, the error is this method only conversion the byteArray half items.

The modify method follow as :
/**
* Nibble conversion. Thanks to our friends at:
* http://www.devx.com/tips/Tip/13540
* @param in the byte array to convert
* @return a java.lang.String based version of they byte array
*/
static String byteArrayToHexString(byte[] in) {
if ((in == null) || (in.length <= 0)) {
return null;
}

StringBuffer out = new StringBuffer(in.length * 2);

for (int i = 0; i < in.length; i++) {
byte ch = (byte) (in & 0xF0); // Strip off high nibble
ch = (byte) (ch >>> 4);

// shift the bits down
ch = (byte) (ch & 0x0F);

// must do this is high order bit is on!
out.append(PSEUDO[(int) ch]); // convert the nibble to a String Character
ch = (byte) (in & 0x0F); // Strip off low nibble
out.append(PSEUDO[(int) ch]); // convert the nibble to a String Character
}

return out.toString();
}

 All   Comments   Change History      Sort Order:
Lars Torunski - [13/Mar/07 06:04 PM ]
Fixed in SVN Revision 413