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

Owner doesn't want to work on Android #25

Open
outofrange opened this issue Feb 4, 2016 · 0 comments
Open

Owner doesn't want to work on Android #25

outofrange opened this issue Feb 4, 2016 · 0 comments

Comments

@outofrange
Copy link
Member

As @perber discovered, Owner can't properly load our properties when running on Android.

The stacktrace is:

java.lang.ExceptionInInitializerError
   at org.obehave.android.application.MyApplication.loadStudy(MyApplication.java:53)
   at org.obehave.android.ui.activities.MainActivity.chooseStudyActivityResult(MainActivity.java:216)
   at org.obehave.android.ui.activities.MainActivity.onActivityResult(MainActivity.java:207)
   at android.app.Activity.dispatchActivityResult(Activity.java:5467)
   at android.app.ActivityThread.deliverResults(ActivityThread.java:3383)
   at android.app.ActivityThread.handleSendResult(ActivityThread.java:3430)
   at android.app.ActivityThread.access$1300(ActivityThread.java:142)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1251)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5118)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
   at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
   at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1148)
   at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
   at java.net.InetAddress.getAllByNameImpl(InetAddress.java:251)
   at java.net.InetAddress.getByName(InetAddress.java:304)
   at java.net.InetSocketAddress.<init>(InetSocketAddress.java:105)
   at java.net.InetSocketAddress.<init>(InetSocketAddress.java:90)
   at libcore.net.url.FtpURLConnection.connectInternal(FtpURLConnection.java:219)
   at libcore.net.url.FtpURLConnection.connect(FtpURLConnection.java:191)
   at libcore.net.url.FtpURLConnection.getInputStream(FtpURLConnection.java:300)
   at java.net.URL.openStream(URL.java:470)
   at org.aeonbits.owner.loaders.PropertiesLoader.load(PropertiesLoader.java:41)
   at org.aeonbits.owner.LoadersManager.load(LoadersManager.java:46)
   at org.aeonbits.owner.Config$LoadType$1.load(Config.java:109)
   at org.aeonbits.owner.PropertiesManager.doLoad(PropertiesManager.java:290)
   at org.aeonbits.owner.PropertiesManager.load(PropertiesManager.java:163)
   at org.aeonbits.owner.PropertiesManager.load(PropertiesManager.java:153)
   at org.aeonbits.owner.PropertiesInvocationHandler.<init>(PropertiesInvocationHandler.java:54)
   at org.aeonbits.owner.DefaultFactory.create(DefaultFactory.java:46)
   at org.aeonbits.owner.ConfigCache.getOrCreate(ConfigCache.java:87)
   at org.aeonbits.owner.ConfigCache.getOrCreate(ConfigCache.java:40)
   at org.obehave.util.properties.AppPropertiesHolder.get(AppPropertiesHolder.java:10)
   at org.obehave.service.Study.<clinit>(Study.java:27)
   at org.obehave.android.application.MyApplication.loadStudy(MyApplication.java:53) 
   at org.obehave.android.ui.activities.MainActivity.chooseStudyActivityResult(MainActivity.java:216) 
   at org.obehave.android.ui.activities.MainActivity.onActivityResult(MainActivity.java:207) 
   at android.app.Activity.dispatchActivityResult(Activity.java:5467) 
   at android.app.ActivityThread.deliverResults(ActivityThread.java:3383) 
   at android.app.ActivityThread.handleSendResult(ActivityThread.java:3430) 
   at android.app.ActivityThread.access$1300(ActivityThread.java:142) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1251) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:136) 
   at android.app.ActivityThread.main(ActivityThread.java:5118) 
   at java.lang.reflect.Method.invokeNative(Native Method) 
   at java.lang.reflect.Method.invoke(Method.java:515) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) 
   at dalvik.system.NativeStart.main(Native Method) 

No idea why Owner thinks it's handling an FtpURLConnection. The URIs are built in PropertiesManager#toURIs(Sources sources, ConfigURIFactory uriFactory) and ConfigURIFactory#newURI(String spec)

Since it's the same piece of code that was touched to fix our ~ expansion issue in Owner, it could be related to some problems when expanding user home on Android (which is done in Util.expandUserHome(String text)):

static String expandUserHome(String text) {
        if (text.equals("~"))
            return system.getProperty("user.home");
        if (text.indexOf("~/") == 0 || text.indexOf("file:~/") == 0 || text.indexOf("jar:file:~/") == 0)
            return text.replaceFirst("~/", fixBackslashForRegex(system.getProperty("user.home")) + "/");
        if (text.indexOf("~\\") == 0 || text.indexOf("file:~\\") == 0 || text.indexOf("jar:file:~\\") == 0)
            return text.replaceFirst("~\\\\", fixBackslashForRegex(system.getProperty("user.home")) + "\\\\");
        return text;
}

As documented by Android, System.getProperty("user.home") is going to return an empty String (or null, not sure what "Empty" means). If it would be an empty String, it would get expanded to file:/obehave/obehave.properties, if it's null, it would throw an NPE because of fixBackslashForRegex.

We're using @Sources({"file:~/obehave/obehave.properties", "classpath:obehave.properties"}) as a source - while an empty user.home can be unexpected and be a bug, I'm still wondering why this would produce to an FTP URI.

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

No branches or pull requests

2 participants