In this guided project, you'll learn how to apply debugging techniques to identify and fix issues in a subscription-based application. You'll practice using breakpoints, inspecting variables, and stepping through code execution.
In this project, we'll apply the scientific method to systematically debug a Subscribe and Save application:
We're working on a Bookstore application, focusing on the code that handles book deliveries, book orders, and checks on a particular title's quantity in stock. Our employees have reported a few odd behaviors of the system, so we want to check it out!
The key classes you'll be working with include:
// Sample code with a bug public boolean processOrder(String bookTitle, int quantity) { // Check if we have enough books in stock if (hasInventory(bookTitle, quantity)) { // Bug: This line doesn't actually update the inventory! // It should be: removeInventory(bookTitle, quantity); checkInventory(bookTitle); // Create and save the order Order order = new Order(bookTitle, quantity); orderRepository.save(order); return true; } return false; }
Clone the project repository and configure your IDE's debugging tools. Make sure you're comfortable with setting breakpoints and stepping through code.
Review the codebase to understand how the Subscribe and Save application works. Pay particular attention to the inventory management system and order processing logic.
Read through the reported bugs and reproduce them with simple test cases. Take note of the expected vs. actual behavior.
Place breakpoints at key locations in the code where you suspect the issues might be occurring. Focus on inventory update methods and order processing logic.
Run the application in debug mode, inspect variables, and step through code execution. Form hypotheses about what's causing each issue and test them systematically.
Implement fixes for each bug you identify. Be sure to document what you changed and why.
Re-run the application with your test cases to ensure your fixes resolved the issues. Also test other functionality to ensure you haven't introduced new bugs.