-
Notifications
You must be signed in to change notification settings - Fork 18
Add isEquivalentTo method to COSBase and COSObject #712
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
base: integration
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import org.verapdf.cos.visitor.ICOSVisitor; | ||
| import org.verapdf.cos.visitor.IVisitor; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.text.DecimalFormat; | ||
| import java.text.DecimalFormatSymbols; | ||
|
|
||
|
|
@@ -45,6 +46,11 @@ public class COSReal extends COSNumber { | |
| protected COSReal() { | ||
| } | ||
|
|
||
| @Override | ||
| public BigDecimal getDecimalValue() { | ||
| return BigDecimal.valueOf(value); | ||
| } | ||
|
Comment on lines
+49
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'Files:\n'
fd -a 'COSReal.java|COSInteger.java' .
printf '\nCOSReal outline:\n'
ast-grep outline src/main/java/org/verapdf/cos/COSReal.java || true
printf '\nCOSInteger outline:\n'
ast-grep outline src/main/java/org/verapdf/cos/COSInteger.java || true
printf '\nRelevant code snippets:\n'
sed -n '1,140p' src/main/java/org/verapdf/cos/COSReal.java
printf '\n---\n'
sed -n '1,125p' src/main/java/org/verapdf/cos/COSInteger.java
printf '\nSearch for COSReal/COSInteger creation and getDecimalValue usage:\n'
rg -n "new COSReal|COSReal\.|getDecimalValue|compareTo.*getDecimalValue" src/main/java/org/verapdf/cos src/main/java -g '*.java' | head -200
printf '\nJava BigDecimal.valueOf behavior probe:\n'
python3 - <<'PY'
import math
values = [float('nan'), float('inf'), float('-inf'), 42.0]
for v in values:
try:
print(f"{v}: finite={math.isfinite(v)}")
print(f" Double.toString={float_repr(v)}")
except NameError as e:
print(f"{v}: finite={math.isfinite(v)}")
PY
printf '\nBehavior note: BigDecimal.valueOf(float/double) rejects NaN/infinity via Double.toString.\n'Repository: veraPDF/veraPDF-parser Length of output: 14662 🏁 Script executed: #!/bin/bash
set -euo pipefail
provider=$(mvn help:evaluate -Dexpression=project.properties.pdfbox-provider -q -DforceStdout 2>/dev/null || true)
if [ -n "$provider" ]; then
echo "current pdfbox-provider=${provider}"
else
echo "pdfbox-provider not available"
fi
# Read the parser/token code around real-number construction without running repo code.
printf '\nPDFStreamParser token.real context:\n'
sed -n '120,190p' src/main/java/org/verapdf/parser/PDFStreamParser.java
printf '\nPostscript operators around division/log/sqrt context:\n'
sed -n '360,505p' src/main/java/org/verapdf/parser/postscript/PSOperator.java
printf '\nPDFStreamParser number token pattern references:\n'
rg -n "real|NUMBER|Double\\.|parseFloat" src/main/java/org/verapdf/parser src/main/java/org/verapdf/pd/function src/main/java/org/verapdf/pd/colors -g '*.java' | head -120Repository: veraPDF/veraPDF-parser Length of output: 11491 🌐 Web query:
💡 Result: In Java, the Citations:
Prevent finite-only real values from being exposed through BigDecimal conversion.
📍 Affects 2 files
🤖 Prompt for AI Agents |
||
|
|
||
| protected COSReal(final double value) { | ||
| this.value = value; | ||
| } | ||
|
|
@@ -88,6 +94,27 @@ public boolean setReal(final double value) { | |
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEquivalentTo(COSBase o) { | ||
| if (this == o) return true; | ||
|
|
||
| if (o.isIndirect()) { | ||
| return isEquivalentTo(o.getDirectBase()); | ||
| } | ||
|
|
||
| if (o instanceof COSReal) { | ||
| COSReal thatReal = (COSReal) o; | ||
| return this.getDecimalValue().compareTo(thatReal.getDecimalValue()) == 0; | ||
| } | ||
|
|
||
| if (o instanceof COSInteger) { | ||
| COSInteger thatInt = (COSInteger) o; | ||
| return this.getDecimalValue().compareTo(thatInt.getDecimalValue()) == 0; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public double get() { | ||
| return this.value; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.