-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't convert 'file:${my.properties}' to a valid URI #134
Comments
Hello @ant1g I had a look at it, and I am sorry you are experiencing this problem, since my goal is to make sure that everything that works with a prior version still works with the updates. But this is not always easy to predict and sometimes this promise has to be broken in order to let things evolve without too many chains. In version 1.0.7 and 1.0.8 internal implementation of owner has been changed in order to use URI instead of URL. Why we changed this? Because URI are more flexible than URL in order to have user specific resource identifiers. The problem with This is demonstrated if you try to run this code (committed here): String spec = "file:${my.properties}";
System.out.println("The parsed URL is: " + new URL(spec)); // this will run fine
System.out.println("The parsed URI is: " + new URI(spec)); // this will run throw the URISyntaxException So when you don't specify the So there are two possible solutions to solve your problem.
if (System.getProperty("my.properties") == null) System.setProperty("my.properties", "/dev/dummy/unexistent");
if (System.getenv().get("my.env") == null) System.setProperty("my.env", "/dev/dummy/unexistent");
MyProperties props = ConfigFactory.create(MyProperties.class); this should solve your problem since So, I would close this issue since a work around is possible and from my point of view, it is the best solution available for the problem. Let me know what do you think or if you have any suggestion. Thanks and have great summer holidays. Luigi. |
Hi Luigi, Thanks for your reply! I was away for some time. I understand your proposed solution, but I am always against adding unnecessary code in the client... Please keep the issue open for a little while, I'll come back to you soon. Best regards! |
Ok Thanks. |
Hi Luigi, Let me know what you think! Cheers! |
By the way, I found something else a bit annoying with the URIs, if you use a windows path as a system property when starting your app, it will fail with the same exception. -Dmy.properties="C:\ProgramData\My Program\my.properties" I will throw a "java.net.URISyntaxException: Illegal character in opaque part at index..." (where the space is...) Reverting to 1.0.5.1 (with URLs) makes it work again. Let me know what do you think of this, perhaps you already have a solution for that. |
I reverted to version 1.0.6 and it worked again |
Just investigating OWNER for use in my own project, when I came across this thread. Thought I'd chime in to point out that URIs are Encoded. See the introductory message in the API doc https://docs.oracle.com/javase/8/docs/api/java/net/URL.html or even http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URL.html). |
Hi. If someone wants to improve this part, it would be welcome. Just note that we need URIs, not just URLs. |
I also ran across the problem of having spaces in the file path. The fix from icirellik should resolved it when it's available. To get around it until a fix is available I replaced spaces with %20. The URI will correctly decode the file path and load the properties as expected. |
Hi,
In the latest 1.0.9, I am seeing an exception being thrown when creating the config from the ConfigFactory.
Here is the exception:
Here is my @sources annotation:
This used to work fine in previous versions (1.0.5.1), as follows:
It seems that the system properties used in the @sources cannot be optional... And that's truly annoying!
Please let me know!
Cheers
The text was updated successfully, but these errors were encountered: