Identifying Boundary Cases - Computer Science

Card 0 of 1

Question

Identify a user error that could occur in this program

UserInput ui = new UserInput(); // input from the user

int s = (Integer)ui;

System.out.println(s);

Answer

The user could input a string and the cast to an (Integer) would cause a runtime exception. If there is a runtime exception, the program will stop and open up vulnerabilities to hackers. Once a hacker knows how to halt a program, they can start input bad data to see a database schema to collect data. One way to fix this would be using a utility method such as parseInt(ui).

Compare your answer with the correct one above

Tap the card to reveal the answer