Skip to content

Commit

Permalink
Fix some CodeQL security warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
NicMcPhee committed Feb 5, 2024
1 parent df7f07c commit 69202d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion server/src/main/java/umm3601/todo/TodoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public TodoDatabase(String todoDataFile) throws IOException {
// the classpath, and returns `null` if it isn't found. We want to throw
// an IOException if the data file isn't found, so we need to check for
// `null` ourselves, and throw an IOException if necessary.
InputStream resourceAsStream = getClass().getResourceAsStream(todoDataFile);
InputStream resourceAsStream = TodoDatabase.class.getResourceAsStream(todoDataFile);
if (resourceAsStream == null) {
throw new IOException("Could not find " + todoDataFile);
}
Expand All @@ -38,6 +38,9 @@ public TodoDatabase(String todoDataFile) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
// Read our user data file into an array of `Todo` objects.
allTodos = objectMapper.readValue(reader, Todo[].class);

// Close the `reader` to free resources.
reader.close();
}

public int size() {
Expand Down
8 changes: 6 additions & 2 deletions server/src/main/java/umm3601/user/UserDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public UserDatabase(String userDataFile) throws IOException {
// the classpath, and returns `null` if it isn't found. We want to throw
// an IOException if the data file isn't found, so we need to check for
// `null` ourselves, and throw an IOException if necessary.
InputStream resourceAsStream = getClass().getResourceAsStream(userDataFile);
InputStream resourceAsStream = UserDatabase.class.getResourceAsStream(userDataFile);
if (resourceAsStream == null) {
throw new IOException("Could not find " + userDataFile);
}
Expand All @@ -37,7 +37,11 @@ public UserDatabase(String userDataFile) throws IOException {
// objects.
ObjectMapper objectMapper = new ObjectMapper();
// Read our user data file into an array of User objects.
allUsers = objectMapper.readValue(reader, User[].class); }
allUsers = objectMapper.readValue(reader, User[].class);

// Close the `reader` to free resources.
reader.close();
}

public int size() {
return allUsers.length;
Expand Down

0 comments on commit 69202d1

Please sign in to comment.