Bug - Fixed Checking sell_price of cyburger results in a NPE

heeheehee

Developer
Staff member
As far as I can tell, this started happening in the past ~day.

Minimal reproducer:
Code:
ash sell_price($coinmaster[the dedigitizer], $item[cyburger])

Stack trace that I got from my script that was crashing:
Code:
class java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "this.name" is null
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "this.name" is null
    at net.sourceforge.kolmafia.AdventureResult.isHP(AdventureResult.java:372)
    at net.sourceforge.kolmafia.AdventureResult.getInstance(AdventureResult.java:1078)
    at net.sourceforge.kolmafia.CoinmasterData.itemBuyPriceInternal(CoinmasterData.java:1181)
    at net.sourceforge.kolmafia.CoinmasterData.itemBuyPrice(CoinmasterData.java:1175)
    at net.sourceforge.kolmafia.textui.RuntimeLibrary.sell_price(RuntimeLibrary.java:6540)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at net.sourceforge.kolmafia.textui.parsetree.LibraryFunction.execute(LibraryFunction.java:75)
    at net.sourceforge.kolmafia.textui.parsetree.FunctionCall.execute(FunctionCall.java:113)
    at net.sourceforge.kolmafia.textui.parsetree.BasicScope.execute(BasicScope.java:403)
    at net.sourceforge.kolmafia.textui.AshRuntime.executeScope(AshRuntime.java:240)
    at net.sourceforge.kolmafia.textui.AshRuntime.execute(AshRuntime.java:190)
    at net.sourceforge.kolmafia.textui.AshRuntime.execute(AshRuntime.java:183)
    at net.sourceforge.kolmafia.textui.command.AshSingleLineCommand.run(AshSingleLineCommand.java:35)
    at net.sourceforge.kolmafia.KoLmafiaCLI.doExecuteCommand(KoLmafiaCLI.java:467)
    at net.sourceforge.kolmafia.KoLmafiaCLI.executeCommand(KoLmafiaCLI.java:433)
    at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:352)
    at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:239)
    at net.sourceforge.kolmafia.swingui.CommandDisplayFrame$CommandQueueHandler.handleQueue(CommandDisplayFrame.java:139)
    at net.sourceforge.kolmafia.swingui.CommandDisplayFrame$CommandQueueHandler.run(CommandDisplayFrame.java:117)
 
My somewhat hacky workaround without fully understanding why CoinmasterData.token is null is to add null checks in isHP() and isMP(). (And for completeness, the other similar methods that dereference a string without checking if it's null first).

Code:
diff --git a/src/net/sourceforge/kolmafia/AdventureResult.java b/src/net/sourceforge/kolmafia/AdventureResult.java
index 7df02e6de1..7edfa66039 100644
--- a/src/net/sourceforge/kolmafia/AdventureResult.java
+++ b/src/net/sourceforge/kolmafia/AdventureResult.java
@@ -369,19 +369,19 @@ public class AdventureResult implements Comparable<AdventureResult>, Cloneable {
   }

   public boolean isHP() {
-    return this.name.equals(AdventureResult.HP);
+    return this.name != null && this.name.equals(AdventureResult.HP);
   }

   public boolean isMP() {
-    return this.name.equals(AdventureResult.MP);
+    return this.name != null && this.name.equals(AdventureResult.MP);
   }

   public boolean isEnergy() {
-    return this.name.equals(AdventureResult.ENERGY);
+    return this.name != null && this.name.equals(AdventureResult.ENERGY);
   }

   public boolean isScrap() {
-    return this.name.equals(AdventureResult.SCRAP);
+    return this.name != null && this.name.equals(AdventureResult.SCRAP);
   }

   public boolean isMonster() {
 
I fixed this by having sell_price of cyburger return 0, since that function only works for Coinmasters that have a single currency used for any particular item, and cyburger requires two currencies to buy it.
 
Back
Top