prevent NPE

This commit is contained in:
Denis Molony 2016-07-22 15:01:17 +10:00
parent f9b43e6968
commit 474603617c
6 changed files with 4 additions and 22 deletions

View File

@ -39,7 +39,7 @@ public class AppleDiskAddress implements DiskAddress
@Override
public boolean matches (DiskAddress that)
{
return this.block == that.getBlock ();
return that != null && this.block == that.getBlock ();
}
@Override

View File

@ -135,7 +135,7 @@ class DiskLayoutSelection implements Iterable<DiskAddress>
public boolean isSelected (DiskAddress da)
{
for (DiskAddress selection : highlights)
if (selection.matches (da)) // NPE 18/7/2016
if (da.matches (selection))
return true;
return false;
}

View File

@ -58,8 +58,6 @@ class Address implements Comparable<Address>
catch (NumberFormatException e)
{
System.out.printf ("NFE: %s%n", sRow);
// for (StackTraceElement ste : Thread.currentThread ().getStackTrace ())
// System.out.println (ste);
}
}

View File

@ -45,20 +45,14 @@ class Condition
public boolean getResult ()
{
// System.out.println (conditionText);
if (conditionExpression == null)
{
// System.out.printf ("creating %s %s %s%n", conditionText, comparator, valueText);
conditionExpression = new Expression (parent, conditionText);
// System.out.printf ("creating %s%n", valueText);
valueExpression = new Expression (parent, valueText);
// System.out.printf ("calculating %s%n", conditionExpression);
conditionExpression.calculate ();
// System.out.printf ("calculating %s%n", valueExpression);
valueExpression.calculate ();
}
// System.out.println ("after calculation");
if (conditionExpression.isError () || valueExpression.isError ())
return false;

View File

@ -16,7 +16,7 @@ class Expression implements Value
// From the reference card:
// Expressions are evaluated strictly from left to right except as modified by
// parentheses. You must start an expression with a +, a digit (0-9), or one of
// the symbols @-(. or #.
// the symbols @-(. or #
// [@IF(@ISERROR(BK24),0,BK24)]
// [@IF(D4=0,0,1)]
@ -40,7 +40,6 @@ class Expression implements Value
{
this.text = text;
String line = checkBrackets (text);
// System.out.printf ("Exp[%s]%n", line);
int ptr = 0;
while (ptr < line.length ())
@ -124,10 +123,6 @@ class Expression implements Value
@Override
public Value calculate ()
{
// System.out.printf ("Calculating: %s%n", text);
// if (text.equals ("@NA"))
// Utility.printStackTrace ();
try
{
Value thisValue = values.get (0);
@ -135,7 +130,6 @@ class Expression implements Value
if (thisValue.isError ())
{
valueType = thisValue.getValueType ();
// System.out.println ("error");
return this;
}
value = thisValue.isNotAvailable () ? 0 : thisValue.getValue ();
@ -151,7 +145,6 @@ class Expression implements Value
if (thisValue.isError ())
{
valueType = thisValue.getValueType ();
// System.out.println ("error");
return this;
}
@ -184,7 +177,6 @@ class Expression implements Value
valueType = ValueType.ERROR;
}
// System.out.printf ("Result: %f%n", value);
return this;
}
@ -254,13 +246,12 @@ class Expression implements Value
System.out.println (input);
return "@ERROR";
}
// System.out.printf ("Old expression:[%s]%n", line);
while (rightBracket < leftBracket)
{
line = line + ")";
rightBracket++;
}
// System.out.printf ("New expression:[%s]%n", line);
}
return line;
}

View File

@ -148,7 +148,6 @@ abstract class Function implements Value
@Override
public double getValue ()
{
// System.out.printf ("Getting value of : %s %s%n", functionName, functionText);
assert valueType == ValueType.VALUE : "Function ValueType = " + valueType;
return value;
}