This has nothing to do with security, one way or another, security is something else. What you might be talking about is that you avoid any problems doing so, so it would be safe because of this, but it’s not about the concept of security that we usually talk about. So if you’ve seen somewhere about malicious code exploring something because of the way you organize the code throw this thing away now. So to answer what you want to know, it makes no sense, found nothing because it doesn’t exist.
There is a lot of confusion of what is said about object orientation because there are different schools on the subject and each one preaches something different, which can already be seen that it should not have as much value as people give for it.
An example of misconception is that attribute is even used in conceptual object orientation, but it makes no sense to call it an attribute in languages, because almost all of them call it field.
The use of getter is questionable, has numerous questions on the subject here, can start by Getters and Setters Methods.
What is said is that you hiding the field behind a method getter gives you more flexibility and hides the detail of implementation, so if one day you need to change something there is easier because it has a indirect, only that. And it is not limited to changing fields.
The question of cloning also seems strange, you have to see the context, in general you should not clone complex objects. Asked like that what you’re talking about doesn’t make sense, it can do in some specific scenario.
As you spoke of frameworks it may be that some require this for an internal motivation, but would have to see the context.
So the question starts from many wrong premises, the path of your learning is all wrong and it mixes things that have no relation whatsoever. My suggestion is to find another source of consultation or change the learning method.
Doing something wrong may have to do with safety, but not because something is changeable or immutable or because it has getter, or because it clones something. Maybe it’s because some component of these lets something external mess with something internal in the code, well then the technology used is insecure and should be discarded, it’s not an object or language orientation problem.
I found another possible reason, depending on the nature of your system and the complexity involved, it could happen that a code of yours can change a date for example that there should not be, since the date is fully exposed, you have no control and can generate some inconsistency, that in practice I could not imagine, but structurally it is possible.
– danilo
I found some explanations on Sonarqube’s website: https://rules.sonarsource.com/java/RSPEC-2384 and on the website Common Weakness Enumeration: http://cwe.mitre.org/data/definitions/374 but it was not convincing to me, the explanation is limited to the application itself, that is, a code within the application itself can change the value before executing another method, can not see real danger.
– danilo