The system I try to debug is relatively complex, so I'll limit it to the classes/methods that I assume to cause the Nullpointer.
I have a class Cloudlet
which among other fields has a unique int cloudletId
used to identify it. I have a class Task extends Cloudlet
. I have a hashMap HashMap<Task,Double> averageComputationTimes
. I have a List<Cloudlet> cloudlets
that contains all the cloudlet objects of interest.
I populate averageComputationCosts
like this:
for (Object cloudlet : getCloudletList()) {
Task t = (Task) cloudlet;
double sum = computationCosts.get(t).values().stream().reduce(0.0,Double::sum);
averageComputationCosts.put(t, sum/computationCosts.get(t).size());
}
At another place in my code I get a Nullpointer:
double max = averageComputationCosts.get(task); // task is again cast and taken from getCloudletList()
Can this happen because the Task
objects that are created are cast from Cloudlet
and hence have a different hashCode
value?