Let’s say I got this test code:
@Test
void shouldNotMoveTreeNodeToParentAsSelf() {
assertThatThrownBy(
() -> service.moveTreeNodeToNewParent(childNode.getId(), childNode.getId())
).isInstanceOf(MoveNodeException.class);
}
There could be times when we are calling trivial getters, like here, because they are methods of one of: Data Transfer Object (DTO), Value Object (VO), Plain Old Java Object (POJO), or JavaBeans. For some, the only reason such getters exists is because the frameworks expect it (i.e., to allow easy serialization and deserialization by frameworks). Otherwise, for example, DTOs are often criticized for not being “purely” object-oriented because they typically violate key principles of Object-Oriented Programming (OOP), specifically encapsulation and behavior, but that’s a longer debate.
What I’m suggesting is that SonarQube should be able to ignore trivial getters that have no behavior, because I don’t think the guesswork argument mentioned in java:S5778 detects false runtime exception is applicable here.