GitHub Codespaces
- In the current repository, go to
<> Code > Codespaces > Create codespace on main
. - Wait until the container finishes building.
- After the Codespaces open, wait until receiving the message that the setup is Done and the terminal closes (Check the image).
- After the setup is done, close the Terminal and open a new window to use the tools.
Local Setup
Follow the instructions presented in Homework 4 - Static Analysis. This setup is not recommended for the purpose of the recitation (it may take sometime to setup).
.
├── README.md
├── projects/
├── infer/
├── pdm/
└── spotbugs/
└── resources/ Presentation from the Recitation
- Open the classes
Student
andApp
and analyze what each one of them does. - In the terminal, change to the infer project directory (
projects/infer
). - Execute the following command in the terminal:
infer --bufferoverrun -- mvn clean package
- Analyze the output generated in the
infer-out
folder. Does it raise any error, and, if so, what program points are responsible?
A list of properties Infer checks can be found here.
- Open the class
CoffeeMachine
to understand its functionality. - In the terminal, change to the pmd-tool project directory (
projects/pmd-tool
) and execute the command:
pmd check --rulesets=ruleset.xml -d src/main/java --report-file pmd-report.txt
- Analyze the
pmd-report.txt
report file generated. Which of the rules inruleset.xml
were triggered and why? - Add three new rules to the
ruleset.xml
that analyzes the code and detects an error. The Index for Java Rules can be found here. Each rule should detect one of the following properties:- Best Practices:
switch
statements should always contain adefault
case, allowing it to process undefined cases. - Code Style: Variable names should be descriptive of the information type they contain. For example,
hasWater
is anint
value, but the prefix assumes the variable is aboolean
. - Error Prone: Values in
if
conditions should not be hardcoded, as changes to a value may require manual change into multiple lines, which is prone to errors. For example, changing the amount of water when callingbuyCappuccino
requires changes to line87
and95
.
- Best Practices:
Note: If you would like to run all the best practice rules for Java, you can include the rule:
<rule ref="category/java/bestpractices.xml" />
- The
spotbugs
folder contains a project that allows you to visualize the participants and spectators of a Volleyball game, as well as, any incoming games between players. - In the terminal, change to the spotbugs project directory (
projects/spotbugs
) and execute the command:
mvn spotbugs:check
To obtain a .xml
report rather than printing in the command line, execute the following command. To read the entire report in one screen, you may want to wrap the text (CMD + Shift + P > Wrap > Toggle Word Wrap
):
mvn spotbugs:spotbugs
- Analyze the types of bugs raised after executing the command.