• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Getting a java.lang.StringIndexOutOfBoundsException Error  RSS feed

 
Ranch Hand
Posts: 1889
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: 5300
142
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: 1889
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: 1889
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: 12561
206
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: 1889
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: 1889
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: 21504
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!