Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

ReplaceAll function - Index out of bounds exception

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does EmailServiceImpl.EMAIL_PADS_SECURITY_NAME_TAG look like ?
 
sankey jain
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79635
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79635
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic