[ 
https://issues.apache.org/jira/browse/CXF-5719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13985329#comment-13985329
 ] 

Alban Deconinck commented on CXF-5719:
--------------------------------------

an example to show you why StringTokenizer is not relevant :

{code:title=Test.java|borderStyle=solid}
import java.util.StringTokenizer;
import java.util.regex.Pattern;

public class Test {

        // precompiled (even if not compiled...) regex (to avoid String.split 
regex compilation)
        static final Pattern    causeSuffixSplitter     = 
Pattern.compile("#*#"/* Message.EXCEPTION_CAUSE_SUFFIX */,
                                                                                
                        Pattern.LITERAL | Pattern.MULTILINE);

        public static void main(String[] args) {
                System.out.println("wrong way");
                String s = "this\nis#sparta#*#oh yeah!";
                StringTokenizer st = new StringTokenizer(s, "#*#");// same as 
"#*"
                while (st.hasMoreElements()) {
                        System.out.println("-----\n" + st.nextElement());
                }

                System.out.println("\nregex way");
                for (String nextElement : causeSuffixSplitter.split(s)) {
                        System.out.println("-----\n" + nextElement);
                }

                // out put in console :

                // "I did not read JDoc" way
                // -----
                // this
                // is
                // ----- <========== should not be splitted in our case !
                // sparta
                // -----
                // oh yeah!
                //
                // regex way (avoid : (parse all String in 1 time)
                // -----
                // this
                // is#sparta
                // -----
                // oh yeah!

        }
}
{{code}}

> NoSuchElementException in ClientFaultConverter when stack trace message 
> contains * or #
> ---------------------------------------------------------------------------------------
>
>                 Key: CXF-5719
>                 URL: https://issues.apache.org/jira/browse/CXF-5719
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.6.10, 2.7.7, 3.0.0-milestone1
>            Reporter: Saad Benbouzid
>              Labels: exception-handling, exceptions, soapfault, stacktrace
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Following stack trace shows up whenever there is a # or a * character in one 
> of the 'Caused By:' clause.
> {code}
> Caused by: java.util.NoSuchElementException
>       at java.util.StringTokenizer.nextToken(StringTokenizer.java:349)
>       at 
> org.apache.cxf.interceptor.ClientFaultConverter.parseStackTrackLine(ClientFaultConverter.java:287)
>       at 
> org.apache.cxf.interceptor.ClientFaultConverter.getCause(ClientFaultConverter.java:278)
>       at 
> org.apache.cxf.interceptor.ClientFaultConverter.setStackTrace(ClientFaultConverter.java:246)
>       at 
> org.apache.cxf.interceptor.ClientFaultConverter.handleMessage(ClientFaultConverter.java:79)
>       at 
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
>       at 
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
>       at 
> org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
>       at 
> org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
>       at 
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
>       at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:845)
> {code}
> For example : 
> {code}
> org.springframework.jdbc.UncategorizedSQLException: Error setting null for 
> parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this 
> parameter or a different jdbcTypeForNull configuration property. Cause: 
> java.sql.SQLException: Type de colonne non valide: 1111
> ; uncategorized SQLException for SQL []; SQL state [99999]; error code 
> [17004]; Type de colonne non valide: 1111; nested exception is 
> java.sql.SQLException: Type de colonne non valide: 1111
>       at 
> org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
>       at 
> org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
>       at 
> org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
>       at 
> org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
>       at 
> org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
>       at com.sun.proxy.$Proxy74.selectOne(Unknown Source)
> {code}
> Because it considers the # (sharp) character as a delimiter.
> That means actual CSF stack trace deserialization does not work for any 
> 'Caused By' clause with a sharp (#) or a star character (#)... which is 
> really unpleasant for customization (see stack trace Apache MyBatis stack 
> trace example above).
> Please avoid *StringTokenizer* splitting in favor of a  *String.split(...)* 
> or a plain old iterator. Because *StringTokenizer* considers not only 
> *Message.EXCEPTION_CAUSE_SUFFIX* as a delimiter, but also each character in 
> it, which are sharp # and star *.
> {quote}
> StringTokenizer is a legacy class that is retained for compatibility reasons 
> although its use is discouraged in new code. It is recommended that anyone 
> seeking this functionality use the split method of String or the 
> java.util.regex package instead.
> {quote}
> {color:red}
> *org.apache.cxf.interceptor.ClientFaultConverter._setStackTrace_*
> {color}
> also see CXF-5231



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to