0

I have the ConcurrentModifcationException raised, on the following snippet, which does not make sense based on what I read on what causes this error (modifying something you have an open iterator over):

    List<Field> kibanaFields = Arrays.asList(KibanaRow.class.getSuperclass().getDeclaredFields());
    kibanaFields.addAll(Arrays.asList(KibanaRow.class.getDeclaredFields()));

Second line, is where it happens. I don't understand this.. even if the first line had some iterator implemented inside, it should have been closed by the time it returns and second method runs.

The purpose here, is to get a list of field names, and later on add the value of @JsonPropertyannotation, on each of the KibanaRow's fields.

1 Answer 1

1

I don't understand the particular reason for a CME. If you showed us the stacktrace we may be able to work it out ....

However what you are trying to do will not work anyway:

List<Field> kibanaFields 
        Arrays.asList(KibanaRow.class.getSuperclass().getDeclaredFields());

This creates a list backed by an array. The list's size is fixed. Elements cannot be added or removed.

kibanaFields.addAll(Arrays.asList(KibanaRow.class.getDeclaredFields()));

If KibanaRow.class.getDeclaredFields() returns a non-empty array, then this will attempt to add more elements to kibanaFields. It can't. An exception should ensue.

One solution to the problem I have identified is to copy the asList result's contents into a new ArrayList; e.g.

List<Field> kibanaFields = new ArrayList<>(Arrays.asList(....));
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this solved the CME and obviously, avoided the other error. Perhaps the CME is the exception for adding to a fixed array? I don't know..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.