You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Will Glass-Husain (JIRA)" <ji...@apache.org> on 2005/09/18 23:05:55 UTC

[jira] Updated: (VELOCITY-81) org.apache.velocity.util.StringUtils.chop(String s, int i, String eol) assumes too much about EOL string

     [ http://issues.apache.org/jira/browse/VELOCITY-81?page=all ]

Will Glass-Husain updated VELOCITY-81:
--------------------------------------

    Bugzilla Id:   (was: 9205)
    Fix Version: 1.5
    Description: 
I'm running Velocity with Texen under WinXP/cygwin/SunJDK1.3.1_02-b02

When I try to generate my pages, I get the following exception:

org.apache.velocity.exception.MethodInvocationException: Invocation of 
method 'chop' in  class org.apache.velocity.util.StringUtils threw exception 
class java.lang.ArrayIndexOutOfBoundsException : null

I've traced this back to the source code and found out that the reason for 
this exception is most probably the fact that Velocity assumes that the 
templates it is working with are written with the same EOL combination that is 
the default for the platform that it is running on.

So, to give you an example, I have templates that have Unix-style linebreaks 
in them and I'm executing Velocity on Windows machine with those templates. 
This breaks the whole thing down.

Workaround? Convert your linebreaks or replace your chop method with this:
    public static String chop(String s, int i, String eol)
    {
        char[] sa = s.toCharArray();
        int length = sa.length;
        length -= i;
        return new String(sa, 0, length);
    }
This will of course break the system, if you have windows-style linebreaks.

So, maybe you can come up with some more elegant fix for this problem? :-)

  was:
I'm running Velocity with Texen under WinXP/cygwin/SunJDK1.3.1_02-b02

When I try to generate my pages, I get the following exception:

org.apache.velocity.exception.MethodInvocationException: Invocation of 
method 'chop' in  class org.apache.velocity.util.StringUtils threw exception 
class java.lang.ArrayIndexOutOfBoundsException : null

I've traced this back to the source code and found out that the reason for 
this exception is most probably the fact that Velocity assumes that the 
templates it is working with are written with the same EOL combination that is 
the default for the platform that it is running on.

So, to give you an example, I have templates that have Unix-style linebreaks 
in them and I'm executing Velocity on Windows machine with those templates. 
This breaks the whole thing down.

Workaround? Convert your linebreaks or replace your chop method with this:
    public static String chop(String s, int i, String eol)
    {
        char[] sa = s.toCharArray();
        int length = sa.length;
        length -= i;
        return new String(sa, 0, length);
    }
This will of course break the system, if you have windows-style linebreaks.

So, maybe you can come up with some more elegant fix for this problem? :-)

    Environment: 
Operating System: Windows XP
Platform: PC

  was:
Operating System: Windows XP
Platform: PC

      Assign To:     (was: Velocity-Dev List)

> org.apache.velocity.util.StringUtils.chop(String s, int i, String eol) assumes too much about EOL string
> --------------------------------------------------------------------------------------------------------
>
>          Key: VELOCITY-81
>          URL: http://issues.apache.org/jira/browse/VELOCITY-81
>      Project: Velocity
>         Type: Bug
>   Components: Source
>     Versions: 1.3-rc1
>  Environment: Operating System: Windows XP
> Platform: PC
>     Reporter: Neeme Praks
>      Fix For: 1.5

>
> I'm running Velocity with Texen under WinXP/cygwin/SunJDK1.3.1_02-b02
> When I try to generate my pages, I get the following exception:
> org.apache.velocity.exception.MethodInvocationException: Invocation of 
> method 'chop' in  class org.apache.velocity.util.StringUtils threw exception 
> class java.lang.ArrayIndexOutOfBoundsException : null
> I've traced this back to the source code and found out that the reason for 
> this exception is most probably the fact that Velocity assumes that the 
> templates it is working with are written with the same EOL combination that is 
> the default for the platform that it is running on.
> So, to give you an example, I have templates that have Unix-style linebreaks 
> in them and I'm executing Velocity on Windows machine with those templates. 
> This breaks the whole thing down.
> Workaround? Convert your linebreaks or replace your chop method with this:
>     public static String chop(String s, int i, String eol)
>     {
>         char[] sa = s.toCharArray();
>         int length = sa.length;
>         length -= i;
>         return new String(sa, 0, length);
>     }
> This will of course break the system, if you have windows-style linebreaks.
> So, maybe you can come up with some more elegant fix for this problem? :-)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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