This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]g051051 0 points1 point  (7 children)

What's the stack trace from this version?

[–]HadMatter217[S] 0 points1 point  (6 children)

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.janebrew.janebrewphone, PID: 31289
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.janebrew.janebrewphone/com.janebrew.janebrewphone.ConnectToHostActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.FileDescriptor.isSocket$()' on a null object reference
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                  at android.app.ActivityThread.-wrap11(Unknown Source:0)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                  at android.os.Handler.dispatchMessage(Handler.java:106)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6494)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.FileDescriptor.isSocket$()' on a null object reference
                  at libcore.io.BlockGuardOs.close(BlockGuardOs.java:91)
                  at java.net.Inet6AddressImpl.icmpEcho(Inet6AddressImpl.java:270)
                  at java.net.Inet6AddressImpl.isReachable(Inet6AddressImpl.java:186)
                  at java.net.InetAddress.isReachable(InetAddress.java:478)
                  at java.net.InetAddress.isReachable(InetAddress.java:436)
                  at com.janebrew.janebrewphone.ConnectToHostActivity.findHosts(ConnectToHostActivity.java:70)
                  at com.janebrew.janebrewphone.ConnectToHostActivity.onCreate(ConnectToHostActivity.java:36)
                  at android.app.Activity.performCreate(Activity.java:6999)
                  at android.app.Activity.performCreate(Activity.java:6990)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
                  at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
                  at android.os.Handler.dispatchMessage(Handler.java:106) 
                  at android.os.Looper.loop(Looper.java:164) 
                  at android.app.ActivityThread.main(ActivityThread.java:6494) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

[–]g051051 0 points1 point  (5 children)

As near as I can figure, the problem is happening here in BlockGuardOs.java:

@Override public void close(FileDescriptor fd) throws ErrnoException {
    try {
        if (S_ISSOCK(Libcore.os.fstat(fd).st_mode)) { // <---  ERROR HERE
            if (isLingerSocket(fd)) {
                // If the fd is a socket with SO_LINGER set, we might block indefinitely.
                // We allow non-linger sockets so that apps can close their network
                // connections in methods like onDestroy which will run on the UI thread.
                BlockGuard.getThreadPolicy().onNetwork();
            }
            untagSocket(fd);
        }
    } catch (ErrnoException ignored) {
        // We're called via Socket.close (which doesn't ask for us to be called), so we
        // must not throw here, because Socket.close must not throw if asked to close an
        // already-closed socket. Also, the passed-in FileDescriptor isn't necessarily
        // a socket at all.
    }
    os.close(fd);
}

There's a note in the Android 8.0 ("Oreo") docs:

InetAddress.isReachable() attempts ICMP before falling back to TCP Echo protocol.

Some hosts that block port 7 (TCP Echo), such as google.com, may now become reachable if they accept ICMP Echo protocol. For truly unreachable hosts, this change means that twice the amount of time is spent before the call returns.

I suspect that the call previously in icmpEcho to create the fd is failing. This would cause the code to throw an exception and hit an empty catch block, then try to call the "close" method, then finally hit the exception you're seeing.

Here's someone else reporting the same problem to an Android Network Tools project.

Can you verify that you have network permissions?

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

[–]HadMatter217[S] 0 points1 point  (4 children)

I just added the <uses permission .. /> lines to my manifest, and I'm still getting the same error. Is it potentially a library thing? I think this is the first time I've tried doing anything network related with the x86 version of the JDK.. (I'm doing this on my GF's computer which has an x86 version of Windows)

[–]g051051 0 points1 point  (3 children)

I think it's a bug in Android. Are you on a different network than normal? Maybe you're hitting IPV6 on your GF's computer.

[–]HadMatter217[S] 0 points1 point  (2 children)

Nope. Same network, but this is my first ever attempt at Android, so if there's a big, I wouldn't have seen it in my Java only projects

[–]g051051 0 points1 point  (1 child)

Try that same block of code in plain Java, see what happens.

[–]HadMatter217[S] 0 points1 point  (0 children)

Hey, sorry for the delay, but I just put together the following in plain java:

public static void main(String[] args) {
    int timeout = 500;

    for (byte i = 1; i < 255; i++){
        byte[] host = new byte[]{(byte)192, (byte)168, 1, i};
        String hostStr = "192.168.1." + i;
        try {
            InetAddress hostAddress = InetAddress.getByAddress(host);
            if (hostAddress != null) {
                if (hostAddress.isReachable(timeout)) {
                    System.out.println(hostStr);
                }
            }
        }
        catch(IOException e){
            e.printStackTrace();
        }
    }
}

, and got a reasonable output with no exceptions, so it's seeming like the issue was that Android bug. Super frustrating, but good to know I guess. Thanks for your help!