Bug 268 - [PredictSys] java.lang.ArrayIndexOutOfBoundsException thrown when starting New Prediction
Summary: [PredictSys] java.lang.ArrayIndexOutOfBoundsException thrown when starting Ne...
Status: RESOLVED FIXED
Alias: None
Product: MovieXXX
Classification: Unclassified
Component: MovieAnalysisEngine (show other bugs)
Version: 1.0
Hardware: PC Windows
: High blocker
Deadline: 2018-11-17
Assignee: clwong274-c
URL:
Depends on:
Blocks:
 
Reported: 2018-11-29 22:09 HKT by tomfong521
Modified: 2018-11-29 23:50 HKT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tomfong521 2018-11-29 22:09:23 HKT
Details:
After select to start a new prediction, an java.lang.ArrayIndexOutOfBoundsException is thrown

Reproducible steps
1. Enter "1" to select "Office Box Prediction" in [System Home]
2. Enter "1" to select "Start New Prediction" in [Office Box Prediction]

Expected results:
- At step (2), no exception or error should be shown and parameters for prediction can be input to process prediction

Actual results:
- At step (2), java.lang.ArrayIndexOutOfBoundsException is thrown and the program is interrupted

Detailed console output:
 >> [Office Box Prediction]
 >> 
 >> 1 Start New Prediction 
 >> 2 Back to Home 
 >> 
 >> Please enter your option [1/2] 
 >> 1
 >> 
 >> Enter genre, director, leading actor, leading actress and budget of new  movie to predict box office (seperate by comma): Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
 >> 	at movieRating.PredictSys.doNewPrediction(PredictSys.java:23)
 >> 	at movieRating.PredictSys.enter(PredictSys.java:64)
 >> 	at movieRating.Main.main(Main.java:24)

Note / Additional information
- This exception does not appear in recommendation feature
Comment 1 clwong274-c 2018-11-29 23:50:29 HKT
Root cause
- Scanner.nextInt method(PredictSys.java:62) does not read the newline character ("\n") entered by hitting "Enter", so after that the call to Scanner.nextLine(PredictSys.java:18) returns after reading that "\n" but before reading parameter for prediction

How to fix
- Added to consume the newline character before calling Scanner.nextLine to read parameter input

Expected behavior
- No exception or error should be shown and parameters for prediction can be input to process prediction

Potential affected areas
- PredictSys

Affected versions
- >=v2

Test cases
1. Enter "1" to select "Office Box Prediction" in [System Home]
2. Enter "1" to select "Start New Prediction" in [Office Box Prediction]

Test result
- At step (2), no exception or error is shown and parameters for prediction can be input to process prediction