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

Comments

Projects
None yet
3 participants
@outofrange

outofrange commented Apr 13, 2015

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 from File source with ~ doesn't create a valid URI on Windows to Config.Sources with ~ doesn't create a valid URI on Windows Apr 13, 2015

@lviggiano

This comment has been minimized.

Show comment
Hide comment
@lviggiano

lviggiano Apr 14, 2015

Owner

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

Owner

lviggiano commented Apr 14, 2015

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

lviggiano added a commit that referenced this issue Apr 14, 2015

@lviggiano

This comment has been minimized.

Show comment
Hide comment
@lviggiano

lviggiano Apr 14, 2015

Owner

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

Owner

lviggiano commented Apr 14, 2015

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

@outofrange

This comment has been minimized.

Show comment
Hide comment
@outofrange

outofrange Apr 14, 2015

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.

outofrange commented Apr 14, 2015

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

This comment has been minimized.

Show comment
Hide comment
@lviggiano

lviggiano Apr 14, 2015

Owner

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.

Owner

lviggiano commented Apr 14, 2015

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

This comment has been minimized.

Show comment
Hide comment
@lviggiano

lviggiano Apr 14, 2015

Owner

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.

Owner

lviggiano commented Apr 14, 2015

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

This comment has been minimized.

Show comment
Hide comment
@outofrange

outofrange Apr 14, 2015

You did a great job already!

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

outofrange commented Apr 14, 2015

You did a great job already!

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

@lviggiano

This comment has been minimized.

Show comment
Hide comment
@lviggiano

lviggiano Jul 22, 2015

Owner

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.

Owner

lviggiano commented Jul 22, 2015

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

This comment has been minimized.

Show comment
Hide comment
@Doogiemuc

Doogiemuc Aug 1, 2017

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

Doogiemuc commented Aug 1, 2017

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