-
Notifications
You must be signed in to change notification settings - Fork 368
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
java.lang.NullPointerException in NetworkInterfacesUtil #1664
Comments
Fixing the |
Please try out the provided PR. If it works for you, I schedule a bugfix release 2.6.4 for next Thursday. |
Thanks for the quick fix, I appreciate that. I have not tried to reproduce the issue myself yet. The crash was reported through analytics and multiple users got the crash. I am not sure yet in what situations this can be null, so it could be hard to reproduce without more information. The reported manufacturers so far are Huawei and Mobvoi Android devices on Android 8/9. |
Maybe turn off wifi and mobile data and then start the app? |
I tried that but no crashes, I looked into the crash again, and noticed that the crash was only reported on Wear OS devices so far. Wear OS devices are smart watches, which are basically just Android devices. However, Internet does work a bit different than on Android phones. Wear OS devices could be using just WiFi. But it could also be a proxy over Bluetooth to the connected Android phone. I guess something there works a bit different which causes |
An additional concern from my side is, that even if this null is fixed, I guess, starting the Connector (and so the open the socket) will also fail. |
Yes that could be the case but wouldn't that be better than a NullPointerException? |
I don't know. My feeling is, it will not work, either for the null or the failing network. We will see ... |
I understand. However, just wrapping the setURI function with a try/catch to catch NullPointerException does not make sense to me. I would prefer the network request to fail or at least that a better exception is thrown. |
It's not about not fixing the null, it's more about the bug after the bugfix .-). |
I merged the PRs. I would appreciate, if it could be tested, what else will be required. For 2.6.x we are somehow limited to bugfixes. The "feature: runs on changing network environment" wasn't considered for 2.6. At least, I would propose to release 2.6.4 only after your feedback about this "overall issue". |
Ok, I found out why |
Sample project (requires Android 6.0+): I was only able to get it to print null on a real phone. Also it does not print null every time, but after switching on/off Wifi a few times it does print null for me.
See |
Nice, if it returns |
Reproduces the NullPointerException with Californium 2.6.3: https://github.com/Thomas-Vos/CaliforniumIssue1664/tree/californium_2.6.3 I used the URL With Californium 2.6.4-SNAPSHOT the CoapResponse is This looks expected to me as Anything else you want me to try? |
No, thanks. It's more about, if that "works for you". If so, should I schedule 2.6.4 for Thursday? |
For me this works fine as it no longer crashes but just receives a null response. (expected behaviour as network is not reachable). A new release would be great. I noticed that Californium does not work again after network is restored. Http requests work fine but Californium not. I also use the new The interesting code is here: https://github.com/Thomas-Vos/CaliforniumIssue1664/blob/californium_3.0.0/app/src/main/java/com/example/californiumissue1664/MainActivity.java See logs below (I added some explanations below):
If I comment out the first Californium request and only execute the second one when network is available again, it works fine. So it seems Californium is still remembering something from the first failed request. Is this expected? For the second request I create a new |
That is more what I'm afraid of. That's that kind of bug after bugfix I has already mentioned. AFAIK, Californium does a lot on "startup" but doesn't retry that. It is not "implemented" to run in changing Network environments. The NetworkInterfacesUtil.clear() should not really be the show-stopper or maker, at least, if no broadcast requests are used. The MTU would mainly affect x509 handshakes, but the defaults should also work. I checkout your sample and try, If I find the cause for failing the second request. |
One idea would be, that the Therefore I would try to use (I will also try to reproduce it. I'm not that sure, if I'm successful.) |
Great, just tried adding The reproducer is maybe not the best, but it works on my phone (Samsung Galaxy S21 Ultra on Android 11). It is hard to make a good sample project if I do not know the exact cause of the issue in my real app. |
But much better than no-one :-). As I wrote, for 2.6 I don't think the NetworkInterfacesUtil.clear() is required. if you want to use it with 2.6.4, could you please check it with that version and without the NetworkInterfacesUtil.clear()? (I still on try to reproduce it ... until now, without luck .. 6x wifi off-on). |
Ok, that works too. Californium 2.6.4-SNAPSHOT with |
Does your phone have Wifi and mobile data? Because the reproducer requires both. Basically what it does is:
|
I used the emulator .. on my Samsung A50 it works ... |
I tested it now a couple of times. Works on my side. |
Great to hear. Thursday is fine for me. Thanks for all the help. |
You're welcome. |
Hi @Thomas-Vos , I currently in preparation for starting to "switch to Californium 4.0". Removing the deprecates, simplifying some historical grown names and updating the minimal java version to support (java 7 gets more and more pain). Do you still use Californium for Android? If so, what is t the minimal java version required for you supporting Android? |
(Just to let you know current Leshan 2.0.0 minimal version is Java 8) |
The corresponding Leshan issue about that move :eclipse-leshan/leshan#924 Note that this is now possible to compile with recent JVM targeting older JVM without toolchains : eclipse-leshan/leshan#1412 Minimal java version to build Leshan is 11 but artifacts are compatible with java 8 |
Thanks Simon for this information! |
Hi @boaks, Thanks for letting me know about this. My app still supports Android 5.0 and higher (Java 8 is starting from Android 8.0). However, there is now a way to use Java 8 language features and APIs on older Android versions like Android 5: https://developer.android.com/studio/write/java8-support So basically, you just publish Californium which uses Java 8 APIs. The library users targeting old Android versions need to follow the guide mentioned above. The app and library code is automatically rewritten to use the backported APIs (called desugaring), like described on the page. I think (almost?) all Java 8 APIs are supported. Supported syntax is described here, and here backported Java 8 and Java 11 APIs. I don't think you will run into any issues. Already using it for other libraries and it is working great. So you do not have to do anything to support this in Californium. But maybe it's a good idea to mention it in the release notes so Android users are aware of this change and can implement this. |
I currently started to work on Californium 4. I hope to prepare the first "update PR" end of next week. I would then be very welcome, if you could check, if that update works for you. |
The first bunch of changes are available in branch If you could spend some time to check, if that works for you with Android, that would be great. |
@boaks, thanks for letting me know. At the moment I am really busy with other tasks so unfortunately I currently do not have the time to test this in detail. Furthermore, in my app Hue Essentials I am using Californium with the IKEA TRADFRI gateway. However, this gateway is no longer available and the upgraded version does not use coap. So my userbase that actually needs Californium is shrinking so updating the library is also less of a priority for me. |
Thanks for your answer. |
I received the following stack trace in my app:
Related Californium code (2.6.3):
https://github.com/eclipse/californium/blob/d6c24198d6891a432ebe67b3044263ef503dcd2e/element-connector/src/main/java/org/eclipse/californium/elements/util/NetworkInterfacesUtil.java#L128-L129
It looks like
NetworkInterface.getNetworkInterfaces()
can return null in some cases, so this should be handled correctly in Californium. You can actually see that it can return null in the Android source code here: https://cs.android.com/android/platform/superproject/+/master:libcore/ojluni/src/main/java/java/net/NetworkInterface.java;l=420;drc=29ea579e1b0541c320448582b6695f0fb9e8aa82The text was updated successfully, but these errors were encountered: