commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clay Bruce <cbr...@quiktrak.com>
Subject [jexl] Unified jexl throws exception when processing white space in file
Date Sun, 22 Apr 2012 19:58:26 GMT
First off Thank you for the excellent library, it has been very useful
in my current project. 

However there are a couple of issues I have found.

 

Using UnifiedJexl with the following script will fail at line 2 and line
4 and line 5. 

Note: line numbers are only for reference, they are not in script 

 

1:<report>

2:

3:$$ var x = 2;

4:

5:     $$ var y = 9;                                        

7:</report>

 

The offending code is the method startsWith which can be found at line
1345  in UnifiedJEXL.java

 

    protected int startsWith(CharSequence sequence, CharSequence
pattern) {

        int s = 0;

        while (Character.isSpaceChar(sequence.charAt(s))) {

            s += 1;

        }

        sequence = sequence.subSequence(s, sequence.length());

        if (pattern.length() <= sequence.length()

                && sequence.subSequence(0,
pattern.length()).equals(pattern)) {

            return s + pattern.length();

        } else {

            return -1;

        }

    }

 

Problem is that sequence is not tested to see if the index is available
before trying to access it.

 

 

Using this non optimized code fixes the issue:

 

    protected int startsWith(CharSequence sequence, CharSequence
pattern) {

                

                String tempString = sequence.toString();

                int patternFoundAt =
tempString.indexOf(pattern.toString());

                if(patternFoundAt != -1 ){

                                int result = patternFoundAt +
pattern.length();

                                if( result >= sequence.length() )

                                                return  -1;

                                else

                                                return result;


                }              

                return patternFoundAt;

    }

 

Code used to load the report is: 

                String templatePath                      =
"template.rpt";

                JexlEngine           engine                  = new
JexlEngine();

                UnifiedJEXL processor   = new UnifiedJEXL(engine);

                Reader scriptReader                       = new
FileReader(templatePath);

 

                UnifiedJEXL.Template template =
PreProcessor.getInstance().prepareTemplate(scriptReader);

 

                JexlContext context = new MapContext();

 

                StringWriter preprocessed = new StringWriter();

                template.evaluate(context, preprocessed );

 

 

This seems like a bug unless I am not using the library correctly?

Thank you once again for great library.

 

Clay

 

 

 

 

 

Clay Bruce

Web Developer

Quiktrak, Inc.

 

Direct Line:  503-214-3199

Private Fax:  800-998-4142

Toll-Free:     800-927-8725 x3199

 

 


 

 

The information contained in this electronic mail message is
confidential information intended only for the use of the individual or
entity named above, and may be privileged. If the reader of this message
is not the intended recipient or the employee or agent responsible to
deliver it to the intended recipient, you are hereby notified that any
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please
immediately notify us by telephone and delete the original message.
Thank You


Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message