From a9c620483d08d0aa0c122864da789d8bebfe5f06 Mon Sep 17 00:00:00 2001 From: Grant Harris <77355424+TwoLettuce@users.noreply.github.com> Date: Tue, 21 Jul 2026 16:18:38 -0600 Subject: [PATCH] Add null check before plain text password assertion bcrypt test ## Issue A student was having trouble finding out why his bcrypt test was failing due to a NullPointerException on line 167 of the DatabaseTests.java file for phase 4. After inspecting his tables during execution and finding that the plain-text password was not being stored anywhere in the database, I looked closer at the test code and noticed that the values read from the database were assumed to be non-null. Under normal conditions, this would not be a problem, since the only data that should exist is the new UserData created by the register endpoint. However, since this student's clearGames function wasn't correctly clearing his games table, there was still a game in the database with null values for whiteUsername and blackUsername. Thus, the ResultSet.getString() method returned null, causing the String.contains method to result in a NullPointerException. ## Solution A simple null-pointer check will help students isolate this error to tests that actually deal with having the games table function correctly. This test will now only fail if there are issues with database setup or if the student is storing plain-text passwords. --- starter-code/4-database/passoff/server/DatabaseTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/starter-code/4-database/passoff/server/DatabaseTests.java b/starter-code/4-database/passoff/server/DatabaseTests.java index 7495157..6c4c267 100644 --- a/starter-code/4-database/passoff/server/DatabaseTests.java +++ b/starter-code/4-database/passoff/server/DatabaseTests.java @@ -166,8 +166,10 @@ private void checkTableForPassword(String table, Connection connection) throws S while (rs.next()) { for (int i = 1; i <= columns; i++) { String value = rs.getString(i); - Assertions.assertFalse(value.contains(TEST_USER.getPassword()), + if (value != null){ + Assertions.assertFalse(value.contains(TEST_USER.getPassword()), "Found clear text password in database"); + } } } }