Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in v2 when the last step in the selector has a predicate index #769

Closed
cjmamo opened this issue Apr 16, 2024 · 0 comments · Fixed by #770
Closed

Regression in v2 when the last step in the selector has a predicate index #769

cjmamo opened this issue Apr 16, 2024 · 0 comments · Fixed by #770
Assignees
Labels
priority: medium type: bug Something isn't working
Milestone

Comments

@cjmamo
Copy link
Member

cjmamo commented Apr 16, 2024

Describe the bug

Quoting the conversation in https://groups.google.com/g/smooks-user/c/hLen9nplpMo/m/8gmWQmpKAQAJ:

Unfortunately, we hit another problem. When the smooks config contains an xpath expression with positions declarations a java.util.ConcurrentModificationException will be thrown. We could reproduce the problem with a modified version of the xml2java example.

The smooks config <jb:bean beanId="header" class="org.smooks.examples.xml2java.model.Header" createOnElement="header[2]">

This will produce a

org.smooks.api.SmooksException: Failed to filter source

            at org.smooks.engine.delivery.sax.ng.SaxNgFilter.doFilter(SaxNgFilter.java:122)

            at org.smooks.engine.delivery.sax.ng.SaxNgFilter.doFilter(SaxNgFilter.java:94)

            at org.smooks.Smooks._filter(Smooks.java:546)

            at org.smooks.Smooks.filterSource(Smooks.java:499)

            at org.smooks.examples.xml2java.Main.runSmooks(Main.java:85)

            at org.smooks.examples.xml2java.JavabeanTest.test(JavabeanTest.java:62)

            at java.base/java.lang.reflect.Method.invoke(Method.java:568)

            at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

            at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Caused by: java.util.ConcurrentModificationException

            at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1013)

            at java.base/java.util.ArrayList$Itr.next(ArrayList.java:967)

            at org.smooks.engine.delivery.sax.ng.SaxNgContentDeliveryConfig.addPositionCounters(SaxNgContentDeliveryConfig.java:243)

            at org.smooks.engine.delivery.sax.ng.SaxNgContentDeliveryConfig.addPositionCounters(SaxNgContentDeliveryConfig.java:232)

            at org.smooks.engine.delivery.sax.ng.SaxNgContentDeliveryConfig.reduceIndex(SaxNgContentDeliveryConfig.java:222)

            at org.smooks.engine.delivery.sax.ng.SaxNgContentDeliveryConfig.get(SaxNgContentDeliveryConfig.java:151)

            at org.smooks.engine.delivery.sax.ng.SaxNgHandler.<init>(SaxNgHandler.java:118)

            at org.smooks.engine.delivery.sax.ng.SaxNgHandler.<init>(SaxNgHandler.java:105)

            at org.smooks.engine.delivery.sax.ng.SaxNgParser.parse(SaxNgParser.java:71)

            at org.smooks.engine.delivery.sax.ng.SaxNgFilter.doFilter(SaxNgFilter.java:110)

            ... 8 more

The complete smooks config looks like this:

<jb:bean beanId="order" class="org.smooks.examples.xml2java.model.Order" createOnElement="order">

    <jb:wiring property="header" beanIdRef="header" />

    <jb:wiring property="orderItems" beanIdRef="orderItems" />

</jb:bean>



<jb:bean beanId="orderItems" class="java.util.ArrayList" createOnElement="order">

    <jb:wiring beanIdRef="orderItem" />

</jb:bean>

<jb:bean beanId="header" class="org.smooks.examples.xml2java.model.Header" createOnElement="header[2]">

    <jb:value property="date" decoder="Date" data="header/date">

        <jb:decodeParam name="format">EEE MMM dd HH:mm:ss z yyyy</jb:decodeParam>

        <jb:decodeParam name="locale-language">en</jb:decodeParam>

        <jb:decodeParam name="locale-country">IE</jb:decodeParam>

    </jb:value>

    <jb:value property="customerNumber" decoder="Long" data="header/customer/@number" />

    <jb:value property="customerName" data="header/customer" />

</jb:bean>



<jb:bean beanId="orderItem" class="org.smooks.examples.xml2java.model.OrderItem" createOnElement="order-item">

    <jb:value property="productId" decoder="Long" data="order-item/product" />

    <jb:value property="quantity" decoder="Integer" data="order-item/quantity" />

    <jb:value property="price" decoder="Double" data="order-item/price" />

</jb:bean>

To Reproduce

Use a selector where the last step has a predicate index like header[2].

Expected behavior

No exception should occur.

Environment

  • Smooks: 2.0.0-RC3
@cjmamo cjmamo added type: bug Something isn't working priority: medium labels Apr 16, 2024
@cjmamo cjmamo added this to the v2.0.0-RC4 milestone Apr 16, 2024
@cjmamo cjmamo self-assigned this Apr 16, 2024
cjmamo added a commit to cjmamo/smooks that referenced this issue Apr 16, 2024
…ig instead of adding it during optimisation phase in order to eliminate situations where one can obtain a ConcurrentModificationException

solve possible race condition in SaxNgVisitorBindings#getAll

throw SmooksException instead of UnsupportedOperationException when condition evaluator cannot be found

feat: use @priority to decide which visitors are fired first

Refs: smooks#769
cjmamo added a commit that referenced this issue Apr 16, 2024
…ig instead of adding it during optimisation phase in order to eliminate situations where one can obtain a ConcurrentModificationException (#770)

solve possible race condition in SaxNgVisitorBindings#getAll

throw SmooksException instead of UnsupportedOperationException when condition evaluator cannot be found

feat: use @priority to decide which visitors are fired first

Refs: #769
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium type: bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant