0

I need to Delete a field In a Class file Using ASM, But im not able to Find anything that works,

for(FieldNode field : classNode.fields) {
    if(field.name.equals("max") && field.value.equals(30)) {
        classNode.fields.remove(field);
        System.out.println("***DELETED " + field.name + " ***");
    }
}

Its giving me a Exeption: DELETED max java.util.ConcurrentModificationException

1
  • See here... Commented Jun 1, 2017 at 12:02

1 Answer 1

1

Deleting something from a Collection while iterating over it is a bad idea and will everytime throw a java.util.ConcurrentModificationException.

If you operate on Java 8 or newer, please consider using Collection::removeIf and give it a predicate lambda to select the items to remove.

In your case this might work:

classNode.fields.removeIf(field -> field.name.equals("max") && field.value.equals(30));
Sign up to request clarification or add additional context in comments.

Comments

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.