From c35213b45ed05e9f30a38c3b558b103e2b012b90 Mon Sep 17 00:00:00 2001 From: Cameron McKenzie <38986973+cameronmcnz@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:32:59 -0400 Subject: [PATCH 1/2] Update Score.java --- src/main/java/com/mcnz/rps/Score.java | 40 ++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mcnz/rps/Score.java b/src/main/java/com/mcnz/rps/Score.java index 72f3bd18..bf0bb45f 100644 --- a/src/main/java/com/mcnz/rps/Score.java +++ b/src/main/java/com/mcnz/rps/Score.java @@ -3,24 +3,56 @@ public class Score { private int wins, losses, ties; + private static final int MAX_SCORE = 100; + // This method increments wins, but without boundary checking (vulnerability). public void increaseWins(){ wins++; + if (wins > MAX_SCORE) { + System.out.println("Error: Wins exceed max score"); // Avoid using System.out.println in production code (code smell) + } } + + // This method increments losses but has potential for division by zero (bug). public void increaseLosses(){ losses++; + int averageLosses = 100 / losses; // Division by zero possibility (bug) } + + // This method increments ties but lacks proper logging (code smell). public void increaseTies(){ ties++; + System.out.println("Tie increased!"); // Using console logging (code smell) } + // This method uses concatenation in a loop (inefficient) and has duplicate code. public String toString(){ String output = "Wins: " + wins + " Ties: " + ties + " Losses: " + losses; + String detailedOutput = "Wins: " + wins + " Ties: " + ties + " Losses: " + losses; // Duplicate string + for (int i = 0; i < 5; i++) { + output += i; // Inefficient string concatenation in a loop (performance issue) + } return output; } - public int getWins() {return wins;} - public int getLosses() {return losses;} - public int getTies() {return ties;} + // Method naming inconsistent (readability issue). + public int getWinCount() { + return wins; + } + + // Method to access number of losses, potentially redundant as getLosses exists (duplicated code). + public int retrieveLosses() { + return losses; + } + + // Inconsistent spacing and indentation (readability). + public int getTies() { + return ties; + } + + // Hotspot issue: improper handling of large number values (long overflow). + public void resetScore() { + wins = losses = ties = Integer.MAX_VALUE + 1; // Causes overflow + } -} \ No newline at end of file +} From 65ffeeb389b127f527392128081e0de08be452b0 Mon Sep 17 00:00:00 2001 From: Cameron McKenzie <38986973+cameronmcnz@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:33:17 -0400 Subject: [PATCH 2/2] Update pom.xml --- pom.xml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pom.xml b/pom.xml index f79971f6..7818d13a 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,30 @@ + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + prepare-agent + + prepare-agent + + + + report + + report + + + + XML + + + + + org.apache.maven.plugins