code4craft / code4craft/xsoup

Valid xpath crashes the lib with NPE

Open
#29 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
474
Forks
148
PR merge metrics
No merged PRs in 30d

Description

Example xml snippet:

<tbody>
    <tr>
        <td>NoLuck</td>
        <td>
            <span>NoHit</span>
        </td>
    </tr>
    <tr>
        <td>whatever</td>
        <td>
            <span>ShouldHit</span>
        </td>
    </tr>
    <tr>
        <td>Again</td>
        <td>
            <span>NoHit</span>
        </td>
    </tr>
</tbody>

XPath:
//table/tbody/tr[contains(td,'whatever']/td/span/text()

It should return: ShouldHit as verified with w3cSchool online tool.
Instead it throws NullPointerException:

Exception in thread "main" java.lang.NullPointerException
at us.codecraft.xsoup.xevaluator.CombiningEvaluator$And.matches(CombiningEvaluator.java:53)
at us.codecraft.xsoup.xevaluator.CombiningEvaluator$And.matches(CombiningEvaluator.java:53)
at us.codecraft.xsoup.xevaluator.StructuralEvaluator$ImmediateParent.matches(StructuralEvaluator.java:84)
at us.codecraft.xsoup.xevaluator.CombiningEvaluator$And.matches(CombiningEvaluator.java:53)
at us.codecraft.xsoup.xevaluator.StructuralEvaluator$ImmediateParent.matches(StructuralEvaluator.java:84)
at us.codecraft.xsoup.xevaluator.CombiningEvaluator$And.matches(CombiningEvaluator.java:53)
at org.jsoup.select.Collector$Accumulator.head(Collector.java:42)
at org.jsoup.select.NodeTraversor.traverse(NodeTraversor.java:31)
at org.jsoup.select.Collector.collect(Collector.java:24)
at us.codecraft.xsoup.xevaluator.DefaultXPathEvaluator.evaluate(DefaultXPathEvaluator.java:29)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied XML and XPath example, then start with CombiningEvaluator.java:53 and follow the stack through StructuralEvaluator.java:84 and DefaultXPathEvaluator.java:29. The work is done when the expression returns “ShouldHit” without throwing a NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.