Pārlūkot izejas kodu

Missing try/catch around parseInt call

Patrick Falls 12 gadi atpakaļ
vecāks
revīzija
adea1579c0

+ 14 - 7
restexpress/src/main/java/hello/controller/MysqlController.java

@@ -35,16 +35,23 @@ public class MysqlController
 
 		// Get the count of queries to run.
 		int count = 1;
-		count = Integer.parseInt(request.getHeader("queries"));
-
-		// Bounds check.
-		if (count > 500)
+		try
 		{
-			count = 500;
+			count = Integer.parseInt(request.getHeader("queries"));
+		
+			// Bounds check.
+			if (count > 500)
+			{
+				count = 500;
+			}
+			if (count < 1)
+			{
+				count = 1;
+			}
 		}
-		if (count < 1)
+		catch(NumberFormatException nfexc)
 		{
-			count = 1;
+			// do nothing
 		}
 
 		// Fetch some rows from the database.