Skip to content
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

Config.Sources with ~ doesn't create a valid URI on Windows #123

Closed
outofrange opened this issue Apr 13, 2015 · 8 comments
Closed

Config.Sources with ~ doesn't create a valid URI on Windows #123

outofrange opened this issue Apr 13, 2015 · 8 comments

Comments

@outofrange
Copy link

If you execute the following simple example on Windows, you will see an URISyntaxException when creating the Config.

import org.aeonbits.owner.Config;
import org.aeonbits.owner.ConfigFactory;

public class Example {
    public static void main(String[] args) {
        // System.setProperty("user.home", System.getProperty("user.home").replace("\\", "/"));

        final BugConfig config = ConfigFactory.create(BugConfig.class);
        System.out.println(config.example());
    }
}

@Config.Sources({"file:~/bug.properties"})
interface BugConfig extends Config {
    @DefaultValue("irrelevant")
    String example();
}

The problem is that System.getProperty("user.home") returns a path sepererated by backslashes on Windows, which isn't allowed in URIs.

Exception in thread "main" java.lang.UnsupportedOperationException: Can't convert 'file:~/bug/bug.properties' to a valid URI
    at org.aeonbits.owner.Util.unsupported(Util.java:124)
    at org.aeonbits.owner.PropertiesManager.toURIs(PropertiesManager.java:134)
    at org.aeonbits.owner.PropertiesManager.<init>(PropertiesManager.java:105)
    at org.aeonbits.owner.DefaultFactory.create(DefaultFactory.java:43)
    at org.aeonbits.owner.ConfigFactory.create(ConfigFactory.java:66)
    at Example.main(Example.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 7: file:C:\Users\outofrange/bug.properties
    at java.net.URI$Parser.fail(URI.java:2848)
    at java.net.URI$Parser.checkChars(URI.java:3021)
    at java.net.URI$Parser.parse(URI.java:3058)
    at java.net.URI.<init>(URI.java:588)
    at org.aeonbits.owner.ConfigURIFactory.newURI(ConfigURIFactory.java:39)
    at org.aeonbits.owner.PropertiesManager.toURIs(PropertiesManager.java:130)
    ... 9 more

There is quite a simple (but ugly) workaround available - just replacing backward- with forward slashes in ${sys:user.home}

Am I overlooking something, or do I really have to tinker with system properties to use ~ expansion in Sources on Windows, like I did in the commented line in main?

If somebody confirms this bug, I'll try to create a pull request for it.

@outofrange outofrange changed the title File source with ~ doesn't create a valid URI on Windows Config.Sources with ~ doesn't create a valid URI on Windows Apr 13, 2015
@lviggiano
Copy link
Collaborator

Thanks for the bug report. I'll verify it soon and fix it asap.

lviggiano pushed a commit that referenced this issue Apr 14, 2015
@lviggiano
Copy link
Collaborator

I think it's fixed on master branch. I packaged a zip file for your convenience if you would like to test it.

@outofrange
Copy link
Author

Awesome! I will test it in a few hours and give you feedback - but looking at your commit, it seems to solve the issue.

When are you planning to release 1.0.9? Of course, I would prefer to just use it as a Maven dependency - if you want to wait with 1.0.9, which is fine, I can add the custom build from master branch as well.

@lviggiano
Copy link
Collaborator

Asap (release). I wish I had more time to do more development on this library, but since I got hired in a company my free time is reduced.

@lviggiano
Copy link
Collaborator

I deployed latest snapshot on this repo: https://oss.sonatype.org/content/repositories/snapshots/

Eventually you can configure your project to use the snapshot repository until next release.

Here you could find some help, eventually: http://stackoverflow.com/questions/7715321/how-to-download-snapshot-version-from-maven-snapshot-repository

I am not familiar with this, but you can try and see if this works for you.

@outofrange
Copy link
Author

You did a great job already!

Thanks for your support. I just tested the snapshot, with success.

@lviggiano
Copy link
Collaborator

Today I release OWNER 1.0.9. Sorry for the long delay.
Hope everything is fine; let me know if there is any problem with it.

@Doogiemuc
Copy link

Just to confirm: I stumbled over this same issue on windows. Using the latest version 1.0.9 solves it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants