@Rule( key = "", name = "Mutable Enum", description = "Rule that checks that Enums are immutable by enforcing fields to be final.", priority = Priority.CRITICAL, tags = { "security", "mutability" })@SqaleMetadata( characteristic = RulesDefinition.SubCharacteristics.SECURITY_COMPLIANCE, remediationCostOffset = "2min", // please don't tell me someone is doing lazy enum configuration... 2 min is enough to add final modifiers, count 2 hours if a developer does not understand why having mutable enum is a really bad practice remediationFunctionType = DefaultDebtRemediationFunction.Type.CONSTANT_ISSUE)
public enum MyEnum { A, B, C;
public String mutableField; // Noncompliant {{Make "mutableField" field final.}} final public String immutableField = ""; // Compliant should not raise an issue}
--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/368da131-bde8-46da-86d6-93af2ff7e1cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
// please don't tell me someone is doing lazy enum configuration... 2 min is enough to add final modifiers, count 2 hours if a developer does not understand why having mutable enum is a really bad practice
Indeed as is the rule does not handle collections / maps, nor any other type of container. "when should you stop digging", and "is it the aim of the rule"
Concerning lazy enums, as I wrote in my previous message
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/dd753230-b26e-437b-af29-8f8ae52b0205%40googlegroups.com.
Indeed as is the rule does not handle collections / maps, nor any other type of container. "when should you stop digging", and "is it the aim of the rule"I thought that SonarQube Java has already some mechanism to detect when collection is for sure mutable. But if not, why not just name this rule Non-final Field in Enum?
Concerning lazy enums, as I wrote in my previous messageOk, but it's just statement. Can you explain in the rule why lazy enums are bad? What are the risks?
An enum type is a special data type that enables for a variable to be a set of predefined constants.
In computer programming, a constant is an identifier with an associated value which cannot be altered by the program during normal execution – the value is constant
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/e1394e0f-26af-42d4-88a0-a0605d67cfba%40googlegroups.com.