Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my return value not properly recognized?

Tags:

java

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
like image 857
Webnet Avatar asked Dec 06 '25 05:12

Webnet


1 Answers

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.

like image 169
Jeroen Vannevel Avatar answered Dec 07 '25 19:12

Jeroen Vannevel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!