Return-Path: Mailing-List: contact cocoon-users-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-users@xml.apache.org Received: (qmail 39293 invoked from network); 10 May 2000 12:55:14 -0000 Received: from anchor-post-31.mail.demon.net (194.217.242.89) by locus.apache.org with SMTP; 10 May 2000 12:55:14 -0000 Received: from adolos.demon.co.uk ([212.228.187.7] helo=powerbookg3x) by anchor-post-31.mail.demon.net with smtp (Exim 2.12 #1) id 12pUYX-0008Gr-0V for cocoon-users@xml.apache.org; Wed, 10 May 2000 12:21:33 +0100 To: cocoon-users@xml.apache.org Subject: Re: [Q] 1.7.3 - Fault with "substring" function = Math.round() fault Date: Wed, 10 May 2000 12:21:02 +0100 From: Stuart Roebuck X-Mailer: Apple Mail (2.130) Message-Id: X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N Problem solved... > Begin forwarded message: > > > On Tue, 9 May 2000, Stuart Roebuck wrote: > > > > > I'm getting a StringIndexOutOfBoundsException trying to use the XPath > > > substring(string, start, length) function. I've tried a simple: > > > > > > > > > > > > And this returns the same stack trace (see below). > > > > java.lang.StringIndexOutOfBoundsException: String index out of range: > > > > substring() works fine for me; i couldn't reproduce your specific error, > > although you've made a mistake in the quoting - you can't nest double > > quotes, so your example should be: > > > > > > > > i don't know if that's any help. > > Thanks for your reply. I introduced the quoting mistake when I was > writing the email - unfortunately that isn't the actual problem. It looks > like the problem is a fault with the Math.round() function on the > implementation of Java 1.2.2 I'm working on. > > I've downloaded the Xalan source, so I'm just going to try patching in a > call to Math.trunc() instead and see if that solves the problem. Don't know quite what the issue is here, but I replaced the code (in file "xml-xalan/src/org/apache/xalan/xpath/FuncSubString.java" of Xalan 1.0.1): ----- { start = Math.round(start); startIndex = (start > 0) ? (int)start-1 : 0; } if(args.size() > 2) { double len = ((XObject)args.elementAt(2)).num(); int end = (int)(Math.round(len)+start)-1; ----- with ----- { start = Math.floor(start + 0.5); startIndex = (start > 0) ? (int)start-1 : 0; } if(args.size() > 2) { double len = ((XObject)args.elementAt(2)).num(); int end = (int)(Math.floor(len + 0.5)+start)-1; ----- converting round(x) calls to floor(x + 0.5), and this has solved the problem. Perhaps this is some jitc problem on my configuration. Regards, Stuart.