You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by bo...@werken.com on 2003/03/06 01:47:21 UTC

[maven-bug] New comment: (MAVEN-315) Jelly scripting in maven.xml

The following comment has been added to this issue:

     Author: Colin Sampaleanu
    Created: Wed, 5 Mar 2003 6:47 PM
       Body:
This actually appears to be a jelly, not maven problem, and is due to a silent failure on trying to supply a long argument to a function (substring) expecting an int. This also points out that jelly does not behave like java in that when you have an expression adding an object which is an int to the literal '1', the result is a long. The following email message I posted sums up what is happening:

-----

Colin Sampaleanu wrote:

> Incze Lajos wrote:
>
>>>> 1. ${antbasename} doesn't change with the iterations.
>>>>
>>>>     
>>>
>>>
>>> Don't forget that you are using ant to set this, not jelly. Ant only sets a property once and does not ever overwrite it.
>>>   
>>
>>
>>
>> OK. Thanks.
>>
>>  
>>
>>>> 2. The various ${namlen} variables mostly don't work.
>>>>
>>>>     
>>>
>>>
>>> What do you mean. 'namelen 1 2' look ok, at 18. 'namelen 5 6 look ok at 18', and 'namelen 7' looks ok at 18. When do any of the namelen variables have wrong values?
>>>   
>>
>>
>>
>> I set these namlenX's, and then try to USE is in ${dirname.substring(namlenX).
>> That is what does not work and don't know why.
>>
>>  
>>
>>>> 3. But sometimes do. Both variables (ext and namlen7) work when was set
>>>>  by some sort of string indexOf() function (??????).
>>>>
>>>> Etc. What on earth is going on? It's only a couple of examples, I have
>>>> others, too. Am I missing something very obvious?
>>>>
>>>> incze
>>>>
>>>>     
>>>
>>>
> It may be related to Longs vs Ints, and coercion of arguments, take a look at this:
>  <goal name="test1">
>    <j:set var="srcbase" value="/opt/data/archive" />
>    <echo>srcbase ........ ${srcbase}</echo>
>
>    <j:set var="source" value="/opt/data/archive/jav/08/01jav.sgm"/>
>    <echo>source ........ ${source}</echo>
>      <j:set var="dirname" value="/opt/data/archive/jav/08"/>
>    <echo>dirname ........ ${dirname}</echo>
>      <j:set var="namlen5" value="${srcbase.length()+1}" />
>    <j:set var="namlen6" value="${size(srcbase)+1}" />
>    <echo>namlen 5 6 ..... ${namlen5} ${namlen6}</echo>
>    <echo>namlen 5 6 classes..... ${namlen5.getClass()} ${namlen6.getClass()}</echo>
>    <j:set var="reldir5" value="${dirname.substring(namlen5)}"/>
>    <echo>reldir5 ........ ${reldir5}</echo>
>    <j:set var="reldir6" value="${dirname.substring(namlen6)}"/>
>    <echo>reldir6 ........ ${reldir6}</echo>
>    <j:set var="namlen7" value="${source.toString().indexOf('j')}" />
>    <echo>namlen 7 ....... ${namlen7}</echo>
>    <echo>namlen 7 class....... ${namlen7.getClass()}</echo>
>    <j:set var="reldir7" value="${dirname.substring(namlen7)}"/>
>    <echo>reldir7 ........ ${reldir7}</echo>
>
>  </goal>
>
> and the output:
> test1:
>    [echo] srcbase ........ /opt/data/archive
>    [echo] source ........ /opt/data/archive/jav/08/01jav.sgm
>    [echo] dirname ........ /opt/data/archive/jav/08
>    [echo] namlen 5 6 ..... 18 18
>    [echo] namlen 5 6 classes..... class java.lang.Long class java.lang.Long
>    [echo] reldir5 ........
>    [echo] reldir6 ........
>    [echo] namlen 7 ....... 18
>    [echo] namlen 7 class....... class java.lang.Integer
>    [echo] reldir7 ........ jav/08
>
> As you can see, namelen 7 is an Integer, while namelen 5 and 6 are Longs.  Now substring takes an int, and I would guess that maybe jelly is silently failing due to an exception trying to pass a long to a method expecting an int. As to why those vars are Longs and not Ints, I would guess it is as a result of the addition operation, where the 1 is treated as a long, and so coerces the entire result to Long. This is not how java works, but jelly expressions don't necessarilly follow correct java rules.


And in fact, in the above, if you change the definition of namlen 5 to
   <j:set var="namlentemp" value="${srcbase.length()+1}" />
   <j:set var="namlen5" value="${namlentemp.intValue()}" />

Then the output becomes

test1:
   [echo] srcbase ........ /opt/data/archive
   [echo] source ........ /opt/data/archive/jav/08/01jav.sgm
   [echo] dirname ........ /opt/data/archive/jav/08
   [echo] namlen 5 6 ..... 18 18
   [echo] namlen 5 6 classes..... class java.lang.Integer class java.lang.Long
   [echo] reldir5 ........ jav/08
   [echo] reldir6 ........
   [echo] namlen 7 ....... 18
   [echo] namlen 7 class....... class java.lang.Integer
   [echo] reldir7 ........ jav/08
BUILD SUCCESSFUL

So indeed, this is a long vs. int issue, where there is a silent failure. As far as I can tell though, this is in no way a maven issue, but rather a jelly issue. Generally, I do find that jelly error checking and reporting is very weak at this point...

----- 
---------------------------------------------------------------------
View the issue:

  http://jira.werken.com/secure/ViewIssue.jspa?key=MAVEN-315


Here is an overview of the issue:
---------------------------------------------------------------------
        Key: MAVEN-315
    Summary: Jelly scripting in maven.xml
       Type: Bug

     Status: Assigned
   Priority: Critical

 Time Spent: Unknown
   Estimate: 0 minutes

    Project: maven
  Component: jelly-integ
   Versions:
             1.0-beta-9

   Assignee: Jason van Zyl
   Reporter: Incze Lajos

    Created: Wed, 5 Mar 2003 5:23 PM
    Updated: Wed, 5 Mar 2003 5:26 PM
Environment: RedHat 8.0 all patches, j2sdk-1.4.1_01, maven HEAD

Description:
Jelly scripting in maven.xml is somehow not safe. The script
attached sets the namlenX vairable in various ways, and then
tries to use the values. The variable is set, the value is
correct, but using it as parameter in a call like
somestring.substring(namlenX) sometimes misteriously fails.
The attached script tries to be self explaining and comes
from a real life example.

When run the attached script namlen1, namlen2 does not work,
namlen3 work. A piece of a run shows this output:

[incze@senorg emnl-transform]$ maven emnl:test
 __  __
|  \/  |__ Jakarta _ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0-beta-9-SNAPSHOT


Attempting to download commons-jelly-SNAPSHOT.jar.
Attempting to download commons-jelly-tags-xml-SNAPSHOT.jar.
Attempting to download commons-jelly-tags-jsl-SNAPSHOT.jar.
emnl:test:
    [echo] srcbase ........ /opt/data/archive
    [echo] source ......... /opt/data/archive/jav/08/01jav.sgm
    [echo] namlen1 ........ srcbase.length()+1 ... 18
    [echo] namlen2 ........ size(srcbase)+1 ...  18
    [echo] namlen3 ........ source.toString().indexOf('j') ... 18
    [echo] filename ....... source.getName() ... 01jav.sgm
    [echo] dirname ........ source.getParent() ... /opt/data/archive/jav/08
    [echo] ext ............ filename.lastIndexOf('.') ... 5
    [echo] basename ext ... filename.substring(0,ext) ... 01jav
    [echo] reldir_18 ...... dirname.substring(18) ... jav/08
    [echo] reldir1 ........ dirname.substring(namlen1) ...
    [echo] reldir2 ........ dirname.substring(namlen2) ...
    [echo] reldir3 ........ dirname.substring(namlen3) ... jav/08
    [echo] reldirJoke ..... dirname.substring(ext) ... data/archive/jav/08
    [echo] reldir4 ........ dirname.substring(srcbase.length()) ... /jav/08
    [echo] reldir5 ........ dirname.substring(srcbase.length()+1) ...
    [echo] srcbase ........ /opt/data/archive
    [echo] source ......... /opt/data/archive/jav/08/02jav.sgm
    [echo] namlen1 ........ srcbase.length()+1 ... 18
    [echo] namlen2 ........ size(srcbase)+1 ...  18
    [echo] namlen3 ........ source.toString().indexOf('j') ... 18
    [echo] filename ....... source.getName() ... 02jav.sgm
    [echo] dirname ........ source.getParent() ... /opt/data/archive/jav/08
    [echo] ext ............ filename.lastIndexOf('.') ... 5
    [echo] basename ext ... filename.substring(0,ext) ... 02jav
    [echo] reldir_18 ...... dirname.substring(18) ... jav/08
    [echo] reldir1 ........ dirname.substring(namlen1) ...
    [echo] reldir2 ........ dirname.substring(namlen2) ...
    [echo] reldir3 ........ dirname.substring(namlen3) ... jav/08
    [echo] reldirJoke ..... dirname.substring(ext) ... data/archive/jav/08
    [echo] reldir4 ........ dirname.substring(srcbase.length()) ... /jav/08
    [echo] reldir5 ........ dirname.substring(srcbase.length()+1) ...
...
etc.
===============================

The worrst of all, that seemingly the usability of the namleX
depends on HOW (??) it was set.


---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://jira.werken.com/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira