From c6e62fee37c9c82921e06ce71f1d2a29a8c9c626 Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 4 Jul 2017 16:55:11 +0200 Subject: [PATCH] Fix NPE in MathType.getType java.lang.NullPointerException at java.lang.String.startsWith(String.java:1428) at org.solovyev.android.calculator.App.find(SourceFile:167) at org.solovyev.android.calculator.math.MathType.getType(SourceFile:285) at org.solovyev.android.calculator.view.TextHighlighter.process(SourceFile:99) at org.solovyev.android.calculator.view.EditorTextProcessor.process(SourceFile:36) at org.solovyev.android.calculator.Editor.onTextChanged(SourceFile:105) at org.solovyev.android.calculator.history.History.org.solovyev.android.calculator.Editor.onTextChanged(SourceFile:15098) at org.solovyev.android.calculator.history.History$2.run(SourceFile:227) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5127) 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:825) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641) at dalvik.system.NativeStart.main(Native Method) --- .../solovyev/common/math/AbstractMathRegistry.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jscl/src/main/java/org/solovyev/common/math/AbstractMathRegistry.java b/jscl/src/main/java/org/solovyev/common/math/AbstractMathRegistry.java index 2a80c703..97797e9c 100644 --- a/jscl/src/main/java/org/solovyev/common/math/AbstractMathRegistry.java +++ b/jscl/src/main/java/org/solovyev/common/math/AbstractMathRegistry.java @@ -23,6 +23,7 @@ package org.solovyev.common.math; import org.solovyev.common.collections.SortedList; +import org.solovyev.common.text.Strings; import java.util.ArrayList; import java.util.Comparator; @@ -168,9 +169,13 @@ public abstract class AbstractMathRegistry implements Math @Nonnull public List getNames() { synchronized (this) { - if (entityNames.isEmpty()) { - for (T entity : entities) { - entityNames.add(entity.getName()); + if (!entityNames.isEmpty()) { + return entityNames; + } + for (T entity : entities) { + final String name = entity.getName(); + if (!Strings.isEmpty(name)) { + entityNames.add(name); } } return entityNames;