ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Masaki Nishikawa (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AXIOM-438) StringIndexOutOfBoundsException occur on rare occasions is when you create a stub object
Date Wed, 01 Aug 2012 07:31:33 GMT
Masaki Nishikawa created AXIOM-438:
--------------------------------------

             Summary: StringIndexOutOfBoundsException occur on rare occasions is when you
create a stub object
                 Key: AXIOM-438
                 URL: https://issues.apache.org/jira/browse/AXIOM-438
             Project: Axiom
          Issue Type: Bug
          Components: API
    Affects Versions: 1.2.10
         Environment: Linux
            Reporter: Masaki Nishikawa
            Priority: Trivial


(Google Translated)
There is a problem with the logic of UUIDGenerator.getInitialUUID, is rare, can occur when
generating the object of the stub is StringIndexOutOfBoundsException.
The cause is because the next "1" s number, places such as "01" when over a string of numeric
Integer.toHexString will decrease.
What are you handling this like why, I do not understand, what the problem be solved by simply
zero-fill?
We appreciate if you fix this bug.

【The appropriate program】

public class UUIDGenerator {
	/* Omitted */
    protected static String getInitialUUID() {
        if (myRand == null) {
            myRand = new Random();
        }
        long rand = myRand.nextLong();
        String sid;
        try {
            sid = InetAddress.getLocalHost().toString();
        } catch (UnknownHostException e) {
            sid = Thread.currentThread().getName();
        }
        StringBuffer sb = new StringBuffer();
        sb.append(sid);
        sb.append(":");
        sb.append(Long.toString(rand));
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new OMException(e);
        }
        md5.update(sb.toString().getBytes());
        byte[] array = md5.digest();
        StringBuffer sb2 = new StringBuffer();
        for (int j = 0; j < array.length; ++j) {
            int b = array[j] & 0xFF;
            sb2.append(Integer.toHexString(b)); // The problem here! Is a string of "1" the
number "01" is Integer.toHexString, reduce the number of digits is
        }
        int begin = myRand.nextInt();
        if (begin < 0) begin = begin * -1;
        begin = begin % 8;
        return sb2.toString().substring(begin, begin + 18).toUpperCase(); // Is raised here
StringIndexOutofBoundsException
    }

    /* Omitted */
}

【Error Trace】

java.lang.StringIndexOutOfBoundsException: String index out of range: 25
	at java.lang.String.substring(Unknown Source)
	at org.apache.axiom.om.util.UUIDGenerator.getInitialUUID(UUIDGenerator.java:94)
	at org.apache.axiom.om.util.UUIDGenerator.getUUID(UUIDGenerator.java:54)
	at org.apache.axis2.description.AxisOperation.<init>(AxisOperation.java:90)
	at org.apache.axis2.description.AxisOperation.<init>(AxisOperation.java:95)
	at org.apache.axis2.description.TwoChannelAxisOperation.<init>(TwoChannelAxisOperation.java:52)
	at org.apache.axis2.description.OutInAxisOperation.<init>(OutInAxisOperation.java:65)
	at org.apache.axis2.description.RobustOutOnlyAxisOperation.<init>(RobustOutOnlyAxisOperation.java:47)
	at org.apache.axis2.client.Stub.addAnonymousOperations(Stub.java:233)
	


(原文)

UUIDGenerator.getInitialUUIDのロジックに問題があり、ごく稀にですが、スタブのオブジェクト生成時にStringIndexOutOfBoundsExceptionが発生します。
原因はInteger.toHexStringで数値を文字列化する際に"01"のような数値だと"1"となり、桁数が減ってしまうためです。
なぜこのような処理をしているのか、理解できていないのですが、単純に0埋めすれば解決する問題でしょうか?
このバグを修正していただけると幸いです。


【該当プログラム】

public class UUIDGenerator {
	/* 省略 */
    protected static String getInitialUUID() {
        if (myRand == null) {
            myRand = new Random();
        }
        long rand = myRand.nextLong();
        String sid;
        try {
            sid = InetAddress.getLocalHost().toString();
        } catch (UnknownHostException e) {
            sid = Thread.currentThread().getName();
        }
        StringBuffer sb = new StringBuffer();
        sb.append(sid);
        sb.append(":");
        sb.append(Long.toString(rand));
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new OMException(e);
        }
        md5.update(sb.toString().getBytes());
        byte[] array = md5.digest();
        StringBuffer sb2 = new StringBuffer();
        for (int j = 0; j < array.length; ++j) {
            int b = array[j] & 0xFF;
            sb2.append(Integer.toHexString(b)); // ここが問題!Integer.toHexStringで"01"の数値が"1"の文字列になり、桁数が減る
        }
        int begin = myRand.nextInt();
        if (begin < 0) begin = begin * -1;
        begin = begin % 8;
        return sb2.toString().substring(begin, begin + 18).toUpperCase(); // ここでStringIndexOutofBoundsExceptionが発生
    }

    /* 省略 */
}


【トレース内容】

java.lang.StringIndexOutOfBoundsException: String index out of range: 25
	at java.lang.String.substring(Unknown Source)
	at org.apache.axiom.om.util.UUIDGenerator.getInitialUUID(UUIDGenerator.java:94)
	at org.apache.axiom.om.util.UUIDGenerator.getUUID(UUIDGenerator.java:54)
	at org.apache.axis2.description.AxisOperation.<init>(AxisOperation.java:90)
	at org.apache.axis2.description.AxisOperation.<init>(AxisOperation.java:95)
	at org.apache.axis2.description.TwoChannelAxisOperation.<init>(TwoChannelAxisOperation.java:52)
	at org.apache.axis2.description.OutInAxisOperation.<init>(OutInAxisOperation.java:65)
	at org.apache.axis2.description.RobustOutOnlyAxisOperation.<init>(RobustOutOnlyAxisOperation.java:47)
	at org.apache.axis2.client.Stub.addAnonymousOperations(Stub.java:233)
	


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ws.apache.org
For additional commands, e-mail: dev-help@ws.apache.org


Mime
View raw message