Search code examples
javavariablesproperties-fileillegalargumentexception

IllegalArgumentException when variable used in properties file


I've created a Java application which uses a .properties file.

Initially I had the below property:

manager.url=https://1.2.3.4/manager-bucket1

As the application and my properties file grew I found that I was duplicating many things in my .properties file so for ease of maintenance I did the following:

manager.ip=1.2.3.4
manager.bucket=manager-bucket1
manager.url=https://${manager.ip}/${manager.bucket}

When I execute my application using the new properties I get an IllegalArgumentException:

Illegal character in path at index 30: https://1.2.3.4/manager-bucket1

java.lang.IllegalArgumentException: Illegal character in path at index 30: https://1.2.3.4/manager-bucket1
at java.net.URI.create(URI.java:852)
at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
at com.service.http.Get.<init>(Get.java:24)
at com.getaccesslogs.AccessCheckUrlConnectionsTest.checkAccessManagerUrl(AccessCheckUrlConnectionsTest.java:145)
at com.getaccesslogs.AccessCheckUrlConnectionsTest.logAccessManagerConnectionTest(AccessCheckUrlConnectionsTest.java:216)
Caused by: java.net.URISyntaxException: Illegal character in path at index 30: https://1.2.3.4/manager-bucket1
at java.net.URI$Parser.fail(URI.java:2822)
at java.net.URI$Parser.checkChars(URI.java:2995)
at java.net.URI$Parser.parseHierarchical(URI.java:3079)
at java.net.URI$Parser.parse(URI.java:3027)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)

I can't see anything obvious that might be causing this. Could it be something to do with the text encoding and if so how can I resolve the issue?


Solution

  • As VGR pointed oout, there was a hidden space character at the end of one of my lines. I identified it by pasting the file contents into Word and clicking the "Show all non-printing characers" button. Once it was removed my application ran without error.