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)
This commit is contained in:
serso 2017-07-04 16:55:11 +02:00
parent 09fe03c1c4
commit c6e62fee37

View File

@ -23,6 +23,7 @@
package org.solovyev.common.math; package org.solovyev.common.math;
import org.solovyev.common.collections.SortedList; import org.solovyev.common.collections.SortedList;
import org.solovyev.common.text.Strings;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
@ -168,9 +169,13 @@ public abstract class AbstractMathRegistry<T extends MathEntity> implements Math
@Nonnull @Nonnull
public List<String> getNames() { public List<String> getNames() {
synchronized (this) { synchronized (this) {
if (entityNames.isEmpty()) { if (!entityNames.isEmpty()) {
return entityNames;
}
for (T entity : entities) { for (T entity : entities) {
entityNames.add(entity.getName()); final String name = entity.getName();
if (!Strings.isEmpty(name)) {
entityNames.add(name);
} }
} }
return entityNames; return entityNames;