| Author |
ReplaceAll function - Index out of bounds exception
|
sankey jain
Ranch Hand
Joined: Apr 29, 2010
Posts: 58
|
|
Hi All,
I am using the below code to replace a HTML tag (EMAIL_PADS_SECURITY_NAME_TAG)
with a value from POJO (dealRequest.getIssuerName())
But, the Value coming from the above POJO is Transocean Jan 2012 Strike $50 Call Option
On this line i get an index out of bound exception
how do i handle this
please help
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
What does EmailServiceImpl.EMAIL_PADS_SECURITY_NAME_TAG look like ?
|
[My Blog]
All roads lead to JavaRanch
|
 |
sankey jain
Ranch Hand
Joined: Apr 29, 2010
Posts: 58
|
|
Christophe Verré wrote:What does EmailServiceImpl.EMAIL_PADS_SECURITY_NAME_TAG look like ?
<PADS SECURITY NAME> this is the value
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
Are you sure the exception happens here ? Wouldn't it be in getStringValue instead ? Can you post the complete stack trace ?
|
 |
sankey jain
Ranch Hand
Joined: Apr 29, 2010
Posts: 58
|
|
Hi Stack Trace Below
Christophe Verré wrote:Are you sure the exception happens here ? Wouldn't it be in getStringValue instead ? Can you post the complete stack trace ?
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
Aahh... sorry... I didn't notice the $ in the replacement string. You have to escape it. Use this instead :
|
 |
sankey jain
Ranch Hand
Joined: Apr 29, 2010
Posts: 58
|
|
Christophe Verré wrote:Aahh... sorry... I didn't notice the $ in the replacement string. You have to escape it. Use this instead :
Hey ..
Thanks .. it solved the issue.
but what is the raitonale behind the issue?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
Apparently $1 through $9 are regex meta sequences for capturing groups. Your $50 was interpreted as the 5th capturing group followed by a 0. See the Javadocs of java.util.regex.Matcher, especially the appendReplacement mehod, for more info.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
$ is used to access matching groups. $50 raises IndexOutOfBoundsException because it tries to access the fifth ($5) matching group, although there may be no such group in your searching pattern.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Well Christophe, we posted the same at exactly the same second. That's a new one for me, usually I'm earlier than the other
|
 |
sankey jain
Ranch Hand
Joined: Apr 29, 2010
Posts: 58
|
|
Rob Prime wrote:Well Christophe, we posted the same at exactly the same second. That's a new one for me, usually I'm earlier than the other
Thanks for the explanation, Now things are clear. ..
Cheers
Sanket
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
Rob Prime wrote:Well Christophe, we posted the same at exactly the same second. That's a new one for me, usually I'm earlier than the other
I can assure you I was a few milliseconds faster
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Rob Prime wrote:Well Christophe, we posted the same at exactly the same second. . . .
Not according to my browser: CV = Today 08:44:46 and RP =Today 08:45:54
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Campbell Ritchie wrote:
Rob Prime wrote:Well Christophe, we posted the same at exactly the same second. . . .
Not according to my browser: CV = Today 08:44:46 and RP =Today 08:45:54
You forgot my post above Christophe's - also at 08:44:46 your time. And I'd say my post was a few milliseconds earlier since it's positioned above Christophe's
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Yes, you are correct. Both at the same second. How do you manage it? Or should I use my new-found powers to swap the order of posts
|
 |
 |
|
|
subject: ReplaceAll function - Index out of bounds exception
|
|
|