• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ReplaceAll function - Index out of bounds exception

 
sankey jain
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does EmailServiceImpl.EMAIL_PADS_SECURITY_NAME_TAG look like ?
 
sankey jain
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:What does EmailServiceImpl.EMAIL_PADS_SECURITY_NAME_TAG look like ?


<PADS SECURITY NAME> this is the value
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aahh... sorry... I didn't notice the $ in the replacement string. You have to escape it. Use this instead :
 
sankey jain
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
$ 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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic