Make error field final in OrasException#3
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Conversation
Fixed issues: - AZ6wRBe-Qw83x_y7ZeLz for java:S1165 rule Generated by SonarQube Agent (task: 8cc3afcb-c255-4063-96cb-ce961daa529f)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Added the
finalmodifier to theerrorfield in the OrasException class to ensure the exception's state is immutable after construction. This addresses a SonarQube issue and follows best practices for exception classes by preventing accidental modification of error field state.View Project in SonarCloud
Fixed Issues
java:S1165 - Make this "error" field final. • MINOR • View issue
Location:
src/main/java/land/oras/exception/OrasException.java:45Why is this an issue?
When a class has all
finalfields, the compiler ensures that the object’s state remains constant. It also enforces a clear design intent of immutability, making the class easier to reason about and use correctly.What changed
This hunk directly fixes the static analysis warning about the
errorfield in theOrasExceptionclass not beingfinal. By adding thefinalmodifier to theerrorfield, the exception class's state becomes immutable after construction, which is the recommended practice for exception classes.SonarQube Remediation Agent uses AI. Check for mistakes.