I have been trying to figure out why this is no longer working. It was all working fine, nothing changed with the object or the function that calls it. I am using Lombok for the getters, setters, and originally the toString but I don't understand how it would hijack a getter. I have also written explicit getters to troubleshoot to no avail.
Class
@Data
class Engineer {
private String name;
private String tech;
@Override
public String toString() {
return "test " + name;
}
}
Method using it
public void example(List<Engineer> engineers) {
//creates keys with toString and creates duplicates
Map<String, Engineer> streamMap = engineers.stream().collect(Collectors.toMap(Engineer::getName, Function.identity()));
//while this one works
Map<String, Engineer> forLoopMap = new HashMap<>();
for(Engineer engineer : engineers) {
forLoopMap.put(engineer.getName, engineer);
}
}
I troubleshot this by making a custom toString with just a string and the name. My original error was a lazy loading issue because toString was trying to get those objects.
After I made the custom toString it started giving me duplicate key errors when I know the names remain unique.
This is not only happening for one list of data but a separate entity list as well using a different unique identifier.
I have been using this stream pattern for awhile and it was working fine but now it is having issues. Any thoughts would be appreciated.
EDIT - TESTS:
- Explicitly made toString (calling getName as a method reference calls toString)
- Explicitly made getName (originally generated by Lombok plugin)
- Works in dev profile but not with prod profile - must be something in the difference