When adding a symbol, a crash will occur if the symbol is not valid.
Researching the issue by observing the stack trace and JSON output when attempting to add the invalid stock symbol "asdf" reveals that the issue is a stock price value of null is passed as a Float value resulting in an InvalidNumberException, killing the StockIntentService and crashing the program.
FATAL EXCEPTION: IntentService[com.sam_chordas.android.stockhawk.service.StockIntentService]
Process: com.example.sam_chordas.stockhawk, PID: 16155
java.lang.NumberFormatException: Invalid float: "null"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseFloat(StringToReal.java:310)
at java.lang.Float.parseFloat(Float.java:300)
at com.sam_chordas.android.stockhawk.rest.Utils.truncateBidPrice(Utils.java:52)
at com.sam_chordas.android.stockhawk.rest.Utils.buildBatchOperation(Utils.java:79)
at com.sam_chordas.android.stockhawk.rest.Utils.quoteJsonToContentVals(Utils.java:33)
at com.sam_chordas.android.stockhawk.service.StockTaskService.onRunTask(StockTaskService.java:127)
at com.sam_chordas.android.stockhawk.service.StockIntentService.onHandleIntent(StockIntentService.java:31)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
Force finishing activity com.example.sam_chordas.stockhawk/com.sam_chordas.android.stockhawk.ui.MyStocksActivity
The fix is to validate the added symbol before using it to generate a new list view. For now the behavior will be to ignore invalid symbols. Later, a Toast or SnackBar message will be provided to flag the error.
Use "asdf" and "bcov" as test symbols. "asdf" should result in a null price value and "ibm" should result in a non-null price value. In both cases the program should not crash after a fix has been applied.