A constructor is removed from its owning class.
The constructor of the class Person in the library has been removed.
public abstract class Person {
private String name;
private int age;
- public Person(String name, int age) {
- this.name = name;
- this.age = age;
- }
public abstract String display();
}
The constructor of the class Team in the library has been removed.
public class Team {
List<Person> members;
- public Team(List<Person> members) {
- this.members = members;
- }
}
Hereafter, we list the broken uses that are currently detected by Maracas.
The method createTeam() is defined within the TeamFactory class.
It invokes the now-removed constructor to create an instance of type Team.
Then, a broken use is reported pointing to the constructor invocation expression.
public class TeamFactory {
public Team createTeam(List<Person> members) {
// Broken use reported here
Team team = new Team(members);
return team;
}
}
The method createEmployee() is defined within the PeopleFactory class.
It invokes the now-removed constructor to create an instance of type Person.
Then, a broken use is reported pointing to the constructor invocation expression.
public class PeopleFactory {
public Person createEmployee(String name, int age) {
// Broken use reported here
Person employee = new Person(name, age) {
@Override
public String display() {
return null;
}
};
return employee;
}
}
The class Employee in a client project extends the abstract class Person.
The constructor invokes the Person constructor via super().
Then, a broken use is reported pointing to the constructor invocation expression.
public class Employee extends Person {
private String role;
public Employee(String name, int age, String role) {
// Broken use reported here
super(name, age);
this.role = role;
}
public String display() {
System.out.println("Employee: " + name);
}
}