Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Getting a java.lang.StringIndexOutOfBoundsException Error  RSS feed

 
Ranch Hand
Posts: 1855
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following generates a java.lang.StringIndexOutOfBoundsException Error

The string being parsed is:

//sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf



I am wanting to point to a file to make an attachment in javax.mail I am not sure if I use a UNC or URL path.
 
Sheriff
Posts: 5015
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a good situation to illustrate why creating an SSCCE (short, self-contained, complete, compilable example) is such a good idea.  What happens when you execute this?
You get a better error, and there is nothing else to get in the way of seeing what's wrong.  Here's what I got:
Can you see what's wrong now?
 
Steve Dyke
Ranch Hand
Posts: 1855
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote: Can you see what's wrong now?



I see it is line 7 but I thought I was using an escape in the replaceAll method "//". Do I have to make provision for the double "//" is the root string?

By the way,  I like your quote by the Apostle Paul in I Corinthians
 
Steve Dyke
Ranch Hand
Posts: 1855
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:Can you see what's wrong now?



Ok, I changed the replaceAll("/", "\\") with replaceAll("/", "\\\\") and am not getting the exception.

But me attachment code is still failing:

UnionNotification: //sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf
UnionNotification: \\sgai-fs02\qmsattachments$\QMSAttachments\Documents\2017\61487_Documents_1506621727828.pdf
SystemOut     O HourBankWebApp: setSendEmailMessageJMailV6: 3: \\sgai-fs02\qmsattachments$\QMSAttachments\Documents\2017\61487_Documents_1506621727828.pdf
SystemOut     O HourBankWebApp: setSendEmailMessageJMailV6: 3: javax.mail.MessagingException: IOException while sending message;
  nested exception is:
java.io.FileNotFoundException: \\sgai-fs02\qmsattachments$\QMSAttachments\Documents\2017\61487_Documents_1506621727828.pdf (A file or directory in the path name does not exist.)

Again, if I paste this path into browser it displays the contents of the file as expected.

 
Sheriff
Posts: 12192
199
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really need to replace / with \ ? What happens if you don't do the replaceAll?
 
Steve Dyke
Ranch Hand
Posts: 1855
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Do you really need to replace / with \ ? What happens if you don't do the replaceAll?



I get this:

SystemOut     O UnionNotification: //sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf
SystemOut     O HourBankWebApp: setSendEmailMessageJMailV6: 3: //sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf
SystemOut     O HourBankWebApp: setSendEmailMessageJMailV6: 3: javax.mail.MessagingException: IOException while sending message;
  nested exception is:
java.io.FileNotFoundException: /sgai-fs02/qmsattachments$/QMSAttachments/Documents/2017/61487_Documents_1506621727828.pdf (A file or directory in the path name does not exist.)
 
Steve Dyke
Ranch Hand
Posts: 1855
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it figured out. It was the attachment code in the javax.mail class. I changed up how the class handled the URL path.

Thanks for all the help.
 
Sheriff
Posts: 21421
94
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only use replaceAll if you need to replace something based on a regular expression. If you want to replace a simple string with another, use replace instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!