Bug 1014300 - java.util.NoSuchElementException thrown when deleting RHQ plugins
java.util.NoSuchElementException thrown when deleting RHQ plugins
Product: RHQ Project
Classification: Other
Component: Core Server (Show other bugs)
Unspecified Unspecified
unspecified Severity high (vote)
: ---
: RHQ 4.10
Assigned To: Thomas Segismont
Mike Foley
Depends On:
Blocks: 1014518
  Show dependency treegraph
Reported: 2013-10-01 12:50 EDT by Thomas Segismont
Modified: 2014-04-23 08:30 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1014518 (view as bug list)
Last Closed: 2014-04-23 08:30:40 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Thomas Segismont 2013-10-01 12:50:13 EDT
Description of problem:
When an admin tries to purge a plugin with a lot of measurement definitions (Oracle plugin), the server fails to delete them (throws java.util.NoSuchElementException)

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Delete Oracle plugin
2. Purge Oracle plugin
3. Wait for the background jobs to run

Actual results:
The server throws java.util.NoSuchElementException

Expected results:
The server purges the plugin
Comment 1 Thomas Segismont 2013-10-01 12:54:04 EDT
Fixed in bug branch bug/1014300

commit 514fef0f46c9d5e0c4546a7a08f27ca6b629614e
Author: Thomas Segismont <tsegismo@redhat.com>
Date:   Tue Oct 1 18:51:20 2013 +0200

Do not use the criteria query iterator remove function

Comment 2 Lukas Krejci 2013-10-01 16:02:12 EDT
I think the error is in the CriteriaQuery iterator implementation rather than in the MeasurementMetadataManagerBean.

The NSEE is thrown on line CriteriaQuery.java#145, which is a call to the underlying iterator.next(). This is directly preceeded by an "if (!iterator.hasNext())" branch.

So the only way (apart from a bug in JDK's ArrayList's iterator impl) line 145 can throw an exception is when the iterator has no more elements, the test for that on line 113 suceeds and the iterator is reinitialized on line 142.

The code therefore assumes that it never gets an empty collection as a result of running a criteria query, which I think is wrong.
Comment 3 Lukas Krejci 2013-10-01 16:14:53 EDT
Well, an empty collection as a last page is not technically a wrong assumption, but it is no longer a correct assumption in the light of possibility of inconsistent results obtained from the criteria query.

The fact that you're only seeing this while deleting stuff en masse is an indicator that in fact that is what you might have uncovered.
Comment 4 Thomas Segismont 2013-10-01 17:02:38 EDT
Thanks for the quick and excellent analysis Lukas.

IIUC, fixing CriteriaQuery iterator implementation will not be a piece of cake. While I think it should be fixed, I also believe that we should commit a workaround for plugin purge very soon.

Besides, I don't understand the real value of using an iterator and iterator#remove here (considering we have to call measurementDefinitionMgr.removeMeasurementDefinition)

Unless I'm wrong and we can fix CriteriaQuery iterator quickly, I'd like to create another BZ to track the iterator problem, and fix the plugin purge with the changes in branch bug/1014300

What do you think?
Comment 5 Lukas Krejci 2013-10-02 04:35:30 EDT
+1, I don't understand the need for the iterator#remove in that method either.
Comment 6 Thomas Segismont 2013-10-02 05:23:37 EDT
Fixed in master

commit 9118dcdb89cbb9cf7a67802b9890f222849579db
Author: Thomas Segismont <tsegismo@redhat.com>
Date:   Tue Oct 1 18:51:20 2013 +0200

Do not use the criteria query iterator which is buggy (besides it adds no value here: more lines and less readable code)
Comment 7 Heiko W. Rupp 2014-04-23 08:30:40 EDT
Bulk closing of 4.10 issues.

If an issue is not solved for you, please open a new BZ (or clone the existing one) with a version designator of 4.10.

Note You need to log in before you can comment on or make changes to this bug.