Reputation: 62366
MyClass.java
protected LinkedBlockingDeque<JobSet> currentWork = new LinkedBlockingDeque<JobSet>();
public LinkedBlockingDeque<JobSet> getCurrentWork() {
return currentWork;
}
Usage
public boolean completeAllWork(CompleteWorkRequest request) {
for (JobSet jobSet : getCurrentWork()) {
//if it's approved, find the workflow process it needs to go to next and put it there
if (request.getApprovedJobSets().contains(jobSet.getUuid().toString())) {
sendToNextWorkflowProcess(jobSet);
} else {
getCurrentWork().remove(jobSet);
logger.info("Rejected JobSet: " + jobSet.getUuid());
}
}
getWorkFromQueue();
return true;
}
It's expecting a JobSet
but getting an Object
. It seems clear to me that it's returning the proper object, so what did I miss?
Error: java: incompatible types
required: com.production.model.JobSet
found: java.lang.Object
Upvotes: 3
Views: 171
Reputation: 8264
It could be that one of your methods is declared to return a LinkedBlockingDeque
instead of a LinkedBlockingDeque<JobSet>
.
getApprovedJobSets()
.getWorkFromQueue()
, perhaps the error is thrown there.Also, does the compiler give any "unchecked type" or "raw type" warnings?
Upvotes: 0
Reputation: 44439
Per the comments: using an Iterator
should solve the problem. My guess is there is interference while iterating the list and simultaneously removing an item, causing the loop to read a deleted value.
Upvotes: 2
Reputation: 111219
You cannot get the error that you mention from the code you have posted so far. This compiles without errors:
import java.util.concurrent.LinkedBlockingDeque;
import java.util.Collection;
class dummy {
static class JobSet {public Object getUuid() {return null;}}
static class CompleteWorkRequest {public Collection getApprovedJobSets() {return null;}};
void getWorkFromQueue() {}
void sendToNextWorkflowProcess(JobSet js) {}
protected LinkedBlockingDeque<JobSet> currentWork = new LinkedBlockingDeque<JobSet>();
public LinkedBlockingDeque<JobSet> getCurrentWork() {
return currentWork;
}
public boolean completeAllWork(CompleteWorkRequest request) {
for (JobSet jobSet : getCurrentWork()) {
//if it's approved, find the workflow process it needs to go to next and put it there
if (request.getApprovedJobSets().contains(jobSet.getUuid().toString())) {
sendToNextWorkflowProcess(jobSet);
} else {
getCurrentWork().remove(jobSet);
//logger.info("Rejected JobSet: " + jobSet.getUuid());
}
}
getWorkFromQueue();
return true;
}
}
Upvotes: 0
Reputation: 177
Actually, if I understand correctly, your error does not come from the return statement, but from the two lines in the else statement. I think you should look at what that methods are returning and try to modify them
Upvotes: 0