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

Uncaught NumberFormatException when comparing (large) integers #1126

Closed
gouttegd opened this issue Feb 22, 2024 · 1 comment
Closed

Uncaught NumberFormatException when comparing (large) integers #1126

gouttegd opened this issue Feb 22, 2024 · 1 comment

Comments

@gouttegd
Copy link
Contributor

This issue was initially reported on the Protégé bug tracker.

Protégé encounters an uncaught NumberFormatException in the OWL API when trying to display the http://www.semanticweb.org/ReproduceError/Testing/SuperClass1#subclass class from the ontology in the attached file:
ReproduceErrorNumberFormatException2.txt

This is because of the large integer value 92740100783 in one of the class expressions defining the class.

In code, the easiest way to reproduce the bug is (assuming df is an OWLDataFactory):

OWLLiteral smallInteger = df.getOWLLiteral(123);
OWLLiteral largeInteger = df.getOWLLiteral("92740100783", df.getIntegerOWLDatatype());
smallInteger.compareTo(largeInteger);

The compareTo call raises a NumberFormatException. I believe the issues lies in the equals(OWLObject) method of the OWLLiteralImplInteger class:

public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!super.equals(obj)) {
        return false;
    }
    if (obj instanceof OWLLiteralImplInteger) {
        OWLLiteralImplInteger other = (OWLLiteralImplInteger) obj;
        return literal == other.literal;
    }
    if (obj instanceof OWLLiteral) {
        return ((OWLLiteral) obj).isInteger()
            && ((OWLLiteral) obj).getLiteral().charAt(0) != '0'
            && literal == ((OWLLiteral) obj).parseInteger();
    }
    return false;
}

because the call to parseInteger() is not protected. If obj happens to be an instance of OWLLiteralImplNoCompression containing the string representation of a large integer, that call will raise the NumberFormatException.

gouttegd added a commit to gouttegd/owlapi that referenced this issue Feb 22, 2024
When comparing integer literal values, if the value we must compare to
is not a OWLLiteralImplInteger, the call to parseInteger could raise a
NumberFormatException if the value is too large to fit into a 32-bit
integer.

This commit catches this possible exception and falls back to comparing
the integer based on their string literal representations.

closes owlcs#1126
@ignazio1977
Copy link
Contributor

Looks like there's also some funny business in the literal parsing, as the value for owl:hasValue does not have a specified datatype and so shouldn't have been parsed to an integer literal.

ignazio1977 pushed a commit that referenced this issue Mar 10, 2024
When comparing integer literal values, if the value we must compare to
is not a OWLLiteralImplInteger, the call to parseInteger could raise a
NumberFormatException if the value is too large to fit into a 32-bit
integer.

This commit catches this possible exception and falls back to comparing
the integer based on their string literal representations.

closes #1126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants