Sonar Qube: Community Build v25.7.0.110598
Lint: 11.20.0.84274
Java: 25
Eclipse: 2025-09
The Java rule S2259 raises an FP, if the switched class is sealed.
Here is a code example fresh from ChatGPT:
// Stable since Java 17
public sealed class Shape permits Circle, Rectangle
{
public double area()
{
return 0.0;
}
}
final class Circle extends Shape
{
private final double radius;
public Circle(double radius)
{
this.radius = radius;
}
@Override
public double area()
{
return Math.PI * radius * radius;
}
}
non-sealed class Rectangle extends Shape
{
private final double width;
private final double height;
public Rectangle(double width, double height)
{
this.width = width;
this.height = height;
}
@Override
public double area()
{
return width * height;
}
}
Having these classes I can switch over a Shape variable using type pattern matching.
Shape shape = …;
switch (shape) // FP!
{
case Circle _ → System.out.println(“Circle”);
case Rectangle _ → System.out.println(“Rectangle”);
}
For this switch s2259 raises an issue and wants me to implement a default case, which is unnecessary due to the sealed Shape class.