NullPointException from Codename One code - java

Since a few days ago and out of nowhere, I sometimes get this NullPointException error:
Exception: java.lang.NullPointerException - Attempt to invoke virtual
method 'boolean java.util.ArrayList.add(java.lang.Object)' on a null
object reference 03-19 09:08:47.785 22799-22820/? W/System.err:
java.lang.NullPointerException: Attempt to invoke virtual method
'boolean java.util.ArrayList.add(java.lang.Object)' on a null object
reference
at com.codename1.r.an.cj(TextArea.java:1199)
at com.codename1.r.an.ci(TextArea.java:865)
at com.codename1.r.an.H(TextArea.java:879)
at com.codename1.r.an.F(TextArea.java:824)
at com.codename1.r.g.b.a(DefaultLookAndFeel.java:907)
at com.codename1.r.an.a(TextArea.java:1259)
at com.codename1.r.l.J(Component.java:2942)
at com.codename1.r.l.K(Component.java:2981)
at com.codename1.r.l.aa(Component.java:1340)
at com.codename1.r.l.af(Component.java:1430) 03-19 09:08:47.786 22799-22820/? W/System.err: at
com.codename1.r.e.a.b(BorderLayout.java:480)
at com.codename1.r.n.a(Container.java:2224)
at com.codename1.r.l.J(Component.java:2942)
at com.codename1.r.l.K(Component.java:2981)
at com.codename1.r.l.aa(Component.java:1340)
at com.codename1.r.l.af(Component.java:1430)
at com.codename1.r.e.b.a(BoxLayout.java:155)
at com.codename1.r.n.bP(Container.java:1715)
at com.codename1.r.n.K(Container.java:1707)
at com.codename1.r.n.bP(Container.java:1720)
at com.codename1.r.n.K(Container.java:1707)
at com.codename1.r.n.bP(Container.java:1720)
at com.codename1.r.n.K(Container.java:1707)
at com.codename1.r.n.bP(Container.java:1720)
at com.codename1.r.n.K(Container.java:1707)
at com.codename1.r.n.a(Container.java:1606)
at com.codename1.r.v.a(Form.java:4046)
at com.codename1.r.l.b(Component.java:2214)
at com.codename1.r.v.b(Form.java:4056)
at com.codename1.r.l.d(Component.java:2187)
at com.codename1.r.l.a(Component.java:2162) 03-19 09:08:47.787 22799-22820/? W/System.err: at
com.codename1.r.l.d(Component.java:2130)
at com.codename1.r.l.c(Component.java:2421)
at com.codename1.r.l.i(Component.java:2365)
at com.codename1.impl.a.s(CodenameOneImplementation.java:613)
at com.codename1.r.q.l(Display.java:1161)
at com.codename1.r.q.k(Display.java:1070)
at com.codename1.r.aj.run(RunnableWrapper.java:120)
at com.codename1.impl.b$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:776)
It doesn't come from my code and I have no idea how to resolve this intermittent error.
Please help me!

Most of these issues occur due to race conditions and violations of the EDT. This means you made changes to the UI in a separate thread either manually created or obtained via: timer, network etc.
We provide an EDT violation detection tool in the simulator which you can enable. As you run with this tool enabled it will print the stack traces for suspected violations. Notice that in some cases it can produce "false positives" but it's normally pretty good at such cases.

Updated
TextArea is an UI component so all interaction should happen on the codenameOne event dispatch thread (EDT).
In the codenameone master file for TextArea, the variable rowText is declared inside the method and has a call prior, so it's not null. So the culprit appears to be rowStrings.add(rowText).
The stack trace is reported at:
https://github.com/codenameone/CodenameOne/blob/master/CodenameOne/src/com/codename1/ui/TextArea.java#L1199
rowStrings is an instance member, but it's not final or protected with locking.
Shai Almog points out in his answer: any manipulation of TextArea should happen on the EDT. TextArea as a UI component should not need to worry about concurrency.

Related

android pre-launch-report - java.lang.RuntimeException with com.google.android.finsky.services.IMarketCatalogService

I have received a pre-launch report on my play.google.com/console:
Android 8.1 (SDK 27)
FATAL EXCEPTION: UIAsyncWorker
Process: com.google.android.music:main, PID: 11466
java.lang.RuntimeException: Attempt to invoke interface method 'boolean com.google.android.finsky.services.IMarketCatalogService.isBackendEnabled(java.lang.String, int)' on a null object reference
at com.google.android.music.utils.async.CallerTracker.reThrowExceptionWithCallerStackTrack(CallerTracker.java:32)
at com.google.android.music.utils.async.TraceableRunnable.runLogged(TraceableRunnable.java:23)
at com.google.android.music.utils.async.LoggedRunnable.run(LoggedRunnable.java:30)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.google.android.music.utils.LoggableHandler.dispatchMessage(LoggableHandler.java:74)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.google.android.finsky.services.IMarketCatalogService.isBackendEnabled(java.lang.String, int)' on a null object reference
at com.google.android.music.tutorial.SignupStatus.checkStoreAvailable(SignupStatus.java:216)
at com.google.android.music.tutorial.SignupStatus.doCheck(SignupStatus.java:154)
at com.google.android.music.tutorial.SignupStatus.launchVerificationCheck(SignupStatus.java:129)
at com.google.android.music.tutorial.SignupStatus.launchVerificationCheckWithFallbackTask(SignupStatus.java:113)
at com.google.android.music.AccountsBroadcastReceiver$1.run(AccountsBroadcastReceiver.java:30)
at com.google.android.music.utils.async.TraceableRunnable.runLogged(TraceableRunnable.java:21)
... 6 more
com.google.android.music - is not my application.
Can I fix the issue or it is a problem in the android device and not in my code?
I'm also seeing this now, in addition to another similar bug affecting a lot of users. It appears to be yet another bug in the Pre-launch reports and not related to our code. My app doesn't use sound, let alone Android Music.
Those affected, please consider reporting it on this bug report.

NullPointerException while setActivity

My app crashes in some devices when try to open an Activity. The problem does not always occur, only on some devices.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.pickerManager = GlobalHolder.getInstance().getPickerManager();
this.pickerManager.setActivity(TempActivity.this); // <== line with error
this.pickerManager.pickPhotoWithPermission();
}
Stacktrace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chillihaze.deskeep/com.libraries.imagepicker.TempActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.libraries.imagepicker.e.a(android.app.Activity)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3122)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1977)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.libraries.imagepicker.e.a(android.app.Activity)' on a null object reference
at com.libraries.imagepicker.TempActivity.onCreate(SourceFile:3)
at android.app.Activity.performCreate(Activity.java:7148)
at android.app.Activity.performCreate(Activity.java:7139)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1293)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102)
I can't reproduce the error on my devices, so I can't test it.
I can't reproduce the error on my devices, so I can't test it.
Ah, you can reproduce the error on all Android devices, you just need to know how ;)
After low memory condition happens, only the current Activity gets recreated at first, previous Activity is recreated on back navigation, and all static variables are nulled out (because the process is technically restarted).
Way to reproduce:
Go to TempActivity in your app
put your application in background with HOME button
click the TERMINATE button in Android Studio
re-launch the app from the launcher
You'll experience this phenomenon.
(In AS 4.0 Canary, this won't work, and instead of using the terminate button, you'd need to use terminal command adb shell am kill your.package.name)
The solution is to use statics with the knowledge and caution that the MAIN activity (the one you defined with <intent-filter>'s MAIN action) is NOT guaranteed to run AT ALL during an Android app's execution, so you should be initializing stuff accordingly.
You can easily return to a DETAIL screen as your First Starting Activity in your app, and the LIST screen would be created only on back navigation.
Also you can check out intent.putExtra( and getIntent() methods which are kept across process death / low memory condition by Android System.
Make sure that the this.pickerManager is not null, on the following line
this.pickerManager.setActivity(TempActivity.this)

Could crashlytics crash on Android?

Here is an overview of a crash on fabric.io
java.lang.IllegalStateException - Fatal exception thrown on Scheduler.Worker thread
rx.exceptions.OnErrorFailedException - an exception originating somewhere in the depth of rx and ending in SafeSubscriber#_onError.
rx.exceptions.CompositeException - 2 exceptions occured
Casual chain - that's the interesting part
Caused by rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =>
at com.crashlytics.android.core.TrimmedThrowableData.<init>(TrimmedThrowableData.java:19)
at com.crashlytics.android.core.TrimmedThrowableData.<init>(TrimmedThrowableData.java:20)
at com.crashlytics.android.core.TrimmedThrowableData.<init>(TrimmedThrowableData.java:20)
at com.crashlytics.android.core.CrashlyticsController.writeSessionEvent(CrashlyticsController.java:1090)
at com.crashlytics.android.core.CrashlyticsController.writeFatal(CrashlyticsController.java:852)
at com.crashlytics.android.core.CrashlyticsController.access$400(CrashlyticsController.java:59)
at com.crashlytics.android.core.CrashlyticsController$6.call(CrashlyticsController.java:292)
at com.crashlytics.android.core.CrashlyticsController$6.call(CrashlyticsController.java:285)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at io.fabric.sdk.android.services.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:75)
at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:30)
at java.lang.Thread.run(Thread.java:776)
retrofit.RetrofitError - 504 Gateway Timeout - probably supposed to be handled in one of the on onError
The version of Rx is 1.3.4. At first I thought that Rx missed the actual exception that occurred in one of the onError methods, but I found this issue https://github.com/ReactiveX/RxJava/issues/3679
and it seems to be resolved, by looking at source code of SafeSubscriber
https://github.com/ReactiveX/RxJava/blob/1.x/src/main/java/rx/observers/SafeSubscriber.java
it seems like rx should report the exception from onError correctly.
So, there is a CompositeException containing a retrofit exception, which is supposed to happen from time to time, and a stacktrace with references to crashlytics code with no references to any app code. I wonder what I should make out of this.

Jackson parse exception while using Guava's RateLimiter

I am using Guava's RateLimiter so I don't hit the max requests per second (I'ts 5..) at the API. It works fine, I never hit the rate limit now but I have a strange problem now. For some reason it gives 1 out of 5 times running the app an exception for one of the 6 calls:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.fasterxml.jackson.databind.JavaType.equals(java.lang.Object)' on a null object reference
at com.fasterxml.jackson.databind.type.ResolvedRecursiveType.equals(ResolvedRecursiveType.java:103)
at com.fasterxml.jackson.databind.type.TypeBindings$AsKey.equals(TypeBindings.java:458)
at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1014)
at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1522)
at com.fasterxml.jackson.databind.util.LRUMap.putIfAbsent(LRUMap.java:64)
at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1274)
at com.fasterxml.jackson.databind.type.TypeFactory._fromParamType(TypeFactory.java:1384)
at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1154)
at com.fasterxml.jackson.databind.type.TypeFactory._resolveSuperInterfaces(TypeFactory.java:1298)
at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1247)
at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1150)
at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:618)
at com.fasterxml.jackson.databind.cfg.MapperConfig.constructType(MapperConfig.java:290)
at com.fasterxml.jackson.databind.cfg.MapperConfig.introspectClassAnnotations(MapperConfig.java:320)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findTypeDeserializer(BasicDeserializerFactory.java:1338)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:481)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3890)
at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3756)
at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2198)
at dk.nykredit.jackson.dataformat.hal.deser.HALBeanDeserializer.deserialize(HALBeanDeserializer.java:27)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2913)
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readJavaType(MappingJackson2HttpMessageConverter.java:179)
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.read(MappingJackson2HttpMessageConverter.java:174)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:89)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:738)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:723)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:544)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:506)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:455)
at nl.app.App.API.RestClient_.getAdviseurs(RestClient_.java:117)
at nl.app.App.Services.AdviseurService.getAdviseur(AdviseurService.java:60)
at nl.app.App.Services.AdviseurService.getAdviseurAsync(AdviseurService.java:49)
at nl.app.App.Services.AdviseurService_.access$101(AdviseurService_.java:19)
at nl.app.App.Services.AdviseurService_$2.execute(AdviseurService_.java:66)
at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:405)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
That exception does not appear to have anything to do with RateLimiter. The stack trace is saying that Spring and/or Jackson tried to call .equals() via reflection on a null reference. My guess would be you're passing null to something you shouldn't be - perhaps you're returning null if the rate limiter doesn't have enough permits?
Without seeing the code in question it's hard to say exactly what's causing this error. Try making an MCVE that replicates the error - it's likely simply creating the MCVE will be enough for you to find the issue.

Android error randomly java.lang.NoClassDefFoundError: com.facebook.internal.Utility

I am using latest Facebook Android SDK and getting that error from dozens of users in my remote crash control app in my latest released apk. I have looked here for such error, but most of the answers are too outdated for last FB SDK, and in this case there are two weird circumstances:
a) The error seems to happen randomly. I have been unable to reproduce it at all on none of my devices.
b) There were no changes in FB logic at all between that release and the previous one, and in the previous release I have never had such error.
Since I couldn't find any relevant difference in the code between such versions, I thought the problem was something wrong could have happened with Android Tools while generating the last apk, but giving the fact that very same apk is the one I am using and have been unable to reproduce the problem and, despite dozens or users are affected, hundreds using the same apk aren't, I discarded also such hypothesis.
Any ideas on how to solve or just debug this thing are welcome.
More info that could be relevant:
All crashes happened in Android 4.0.3 or older. The highest percentage is for 2.3.6 with 48% of all the crashes.
That class is actually exported in the APK. I have checked it by unzipping the apk and using dexdump to see what is inside classes.dex. I couldn't expected other thing, since it works perfectly in all my devices and if the class weren't there, it would not.
$ ~/android-sdks/build-tools/21.1.1/dexdump classes.dex | grep 'com.facebook.internal.Utility$1'
Class descriptor : 'Lcom/facebook/internal/Utility$1;'
#0 : (in Lcom/facebook/internal/Utility$1;)
#1 : (in Lcom/facebook/internal/Utility$1;)
#2 : (in Lcom/facebook/internal/Utility$1;)
#0 : (in Lcom/facebook/internal/Utility$1;)
#0 : (in Lcom/facebook/internal/Utility$1;)
#1 : (in Lcom/facebook/internal/Utility$1;)
#2 : (in Lcom/facebook/internal/Utility$1;)
#3 : (in Lcom/facebook/internal/Utility$1;)
It seems to fail after an invocation of a Utility's static method from loadAppSettingsAsync, that happens to be a static method within the same class. So, if the com.facebook.internal.Utility class does not exist or couldn't be loaded, how it is possible that com.facebook.internal.Utility.loadAppSettingsAsync is executed in first place? and if it exists and it is loaded, why is NoClassDefFoundError thrown on com.facebook.internal.Utility? I am so f* lost...
Here the stack from splunk mint (formerly known as bugsense), I just changed the name of the app. I retraced it with the proguard map file, but it seems it missed some line numbers anyway:
java.lang.NoClassDefFoundError: com.facebook.internal.Utility$1
at com.facebook.internal.Utility.void loadAppSettingsAsync(android.content.Context,java.lang.String)(Unknown Source)
at com.facebook.Settings.void sdkInitialize(android.content.Context)(Unknown Source)
at com.facebook.UiLifecycleHelper.<init>(Unknown Source)
at net.iberdroid.androidgames.framework.impl.AndroidGame.void onCreate(android.os.Bundle)(Unknown Source)
at com.marzoa.ruletafree.xmas2012.RuletaAfortunadaGame.void onCreate(android.os.Bundle)(Unknown Source)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3770)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.facebook.internal.Utility$1 in loader dalvik.system.PathClassLoader[/data/app/com.marzoa.ruletafree.xmas2012-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
... 18 more
As the NoClassDefFoundError occurs in loadAppSettingsAsync at an anonymous implementation of AsyncTask it seems to be the same problem like this NoClassDefFoundError - Android 2.3.X
Its a bug in google play services. (https://code.google.com/p/android/issues/detail?id=81083)
Try to add following into your Application#onCreate() method as described in the answer of the referred issue.
try {
Class.forName("android.os.AsyncTask");
}
catch(Throwable ignore) {
// ignored
}
Firstly, be sure that you are checking for the right class. According to the error message, the "missing" class is com.facebook.internal.loadAppSettingsAsync$1. Note the $1!! That means we are talking about an anonymous inner class that is declared within the Utility.loadAppSettingsAsync.
Second, java.lang.NoClassDefFoundError can have a number of causes:
The class may be missing.
The class could be present but unloadable for some reason.
The class could be loadable, but a previous attempt to initialize it ... or some dependent class ... has failed.
The last case typically happens if a static initialization or static initializer block throws an unchecked exception the first time it was run. (You will typically a log message for this exception.) Once the class initialization has failed once, the class is marked as broken. This stops the class and any other classes that depends on it from being initialized.

Categories