BaseXdb / basex

BaseX Main Repository.
http://basex.org
BSD 3-Clause "New" or "Revised" License
661 stars 268 forks source link

XQuery: Bug: Unexpected exception of division by zero #2189

Closed Twilight-Shuxin closed 1 year ago

Twilight-Shuxin commented 1 year ago

Description of the Problem

Given this XML document:

<A1 id="1">-1</A1>

and XPath Query

//A1[(text() * 0) = 6]

BaseX throws the exception

java.io.IOException: Stopped at C:/BaseX/basex/bin/, 1/22:
[FOAR0001] 6 cannot be divided by zero.

Expected Behavior

Should not throw exception but execute successfully and return empty result set as Saxon & Exist DB since no division operation is involved.

Steps to Reproduce the Behavior

Using BaseX Client:

  1. Create database create database test
  2. Insert XML file into database put test.xml path/to/file
  3. Execute XPath query xquery //A1[(text() * 0) = 6] (Note: Directly executing <A1 id="1">-1</A1>//A1[(text() * 0) = 6] does not trigger the bug

Do you have an idea how to solve the issue?

No response

What is your configuration?

BaseX version: 10.4 on Windows (Also reproduced on the latest stable snapshot 10.5 provided in https://files.basex.org/releases/latest/)

ChristianGruen commented 1 year ago

True, and fixed. The reason for the unexpected error message (and the previous one) was that arithmetic expressions are simplified at compile time:

//A1[(text() * 2) = 6]
→ //A1[text() = 6 div 2]
→ //A1[text() = 3]

In the latest snapshot, I have restricted the rewriting rules to positive numbers excluding 0.

Twilight-Shuxin commented 1 year ago

Thanks!