From 94297e75b9b87eb18d7f13c3f291ebe48d1d5f8b Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Santos Souza de Miranda Date: Sat, 6 Dec 2025 22:30:51 -0300 Subject: [PATCH] Add id validation and improve code formatting in updateSamplingRate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhance input validation and code quality in the SamplingRate service: - Add null check for id parameter in updateSamplingRate() method to prevent potential NullPointerException when calling repository.findById() - Standardize indentation throughout the updateSamplingRate() method body, improving code readability and consistency with project style guidelines This complements the previous validation improvements by ensuring all method parameters are properly validated before use, creating a more defensive and robust API surface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../samplingrate/SamplingRateService.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/mediamanager/service/samplingrate/SamplingRateService.java b/src/main/java/com/mediamanager/service/samplingrate/SamplingRateService.java index b347815..005e8e5 100644 --- a/src/main/java/com/mediamanager/service/samplingrate/SamplingRateService.java +++ b/src/main/java/com/mediamanager/service/samplingrate/SamplingRateService.java @@ -40,19 +40,22 @@ public class SamplingRateService { } public Optional updateSamplingRate(Integer id, String value) { - logger.info("Updating sampling rate:{}", value); - if (value == null || value.trim().isEmpty()) { - throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty"); - } - Optional existingSamplingRate = repository.findById(id); - if(existingSamplingRate.isEmpty()) { - logger.warn("Sampling rate not found with id:{}", id); - return Optional.empty(); - } - SamplingRate samplingRate = existingSamplingRate.get(); - samplingRate.setValue(value); - SamplingRate updatedSamplingRate = repository.update(samplingRate); - return Optional.of(updatedSamplingRate); + if (id == null) { + throw new IllegalArgumentException("ID cannot be null"); + } + logger.info("Updating sampling rate:{}", value); + if (value == null || value.trim().isEmpty()) { + throw new IllegalArgumentException("Sampling-Rate value cannot be null or empty"); + } + Optional existingSamplingRate = repository.findById(id); + if(existingSamplingRate.isEmpty()) { + logger.warn("Sampling rate not found with id:{}", id); + return Optional.empty(); + } + SamplingRate samplingRate = existingSamplingRate.get(); + samplingRate.setValue(value); + SamplingRate updatedSamplingRate = repository.update(samplingRate); + return Optional.of(updatedSamplingRate); } public boolean deleteSamplingRate(Integer id) {