Page 1 of 1

Re: About Question enthuware.ocpjp.v11.2.3400 :

Posted: Fri Apr 09, 2021 9:48 pm
by alfredo.zuloaga
This is not true make clone doesn't work

public static class Shape {
Point[] vertices;

public Shape(Point[] verts) {
this.vertices = verts;
}

public Point[] getVertices() {
return vertices.clone();
}

public void setVertices(Point[] vertices) {
this.vertices = vertices.clone();
}
}

public static void main(String[] args) throws Exception {

Shape shape = new Shape(null);

Point[] vertices = {new Point(1, 2)};
shape.setVertices(vertices);
Point[] vertices1 = shape.getVertices();
vertices[0].x = 12;

System.out.println(vertices[0].x + "--" + vertices1[0].x);
}

Re: About Question enthuware.ocpjp.v11.2.3400 :

Posted: Fri Apr 09, 2021 10:23 pm
by admin
The objective here is to apply the Java Security Guidelines for the purpose of the exam and not to design a fool proof system where all the requirements are explicitly given.
In this case, all you want to do is to ensure that the vertices array immutable. Yes, it is true that Point objects themselves can change but that is not important for the purpose of this question.

In real world application, one would know what level of immutability is required, and may be there, even the Point class may be required to be made immutable. Depends on requirements.

For the purpose of the exam, just apply the security guidelines as given here: https://www.oracle.com/java/technologie ... guide.html

Do not overthink it.