The visibility of a library field is decreased by modifying its access modifier.
The access modifier of the field name
in the library class Person
is changed from public
to protected
.
public class Person {
- public String name;
+ protected String name;
}
Hereafter, we list the broken uses that are currently detected by Maracas.
The access modifier of the field name
in the library class Person
is changed from public
to private
.
public class Person {
- public String name;
+ private String name;
}
The method displayPerson
—defined in the PeopleInfo
class in a client project—accesses the now-private name
field.
Then, a broken use is reported pointing to the field access expression.
public class PeopleInfo {
public void displayPerson(Person person) {
// Broken use reported here
String personName = person.name;
System.out.println(personName);
}
}
The access modifier of the field name
in the library class Person
is changed from public
to package-private (by removing the modifier).
public class Person {
- public String name;
+ String name;
}
The method displayPerson
—defined in the PeopleInfo
class in a client project—accesses the now-package-private name
field.
Then, a broken use is reported pointing to the field access expression.
public class PeopleInfo {
public void displayPerson(Person person) {
// Broken use reported here
String personName = person.name;
System.out.println(personName);
}
}
The access modifier of the field name
in the library class Person
is changed from public
to protected
.
public class Person {
- public String name;
+ protected String name;
}
The method displayPerson
—defined in the PeopleInfo
class in a client project—accesses the now-protected name
field.
Then, a broken use is reported pointing to the field access expression.
public class PeopleInfo {
public void displayPerson(Person person) {
// Broken use reported here
String personName = person.name;
System.out.println(personName);
}
}