Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

StringBuilderConstructors01 exposes in fact a violation_witness due to overflow when following Java Spec #1103

Open
pointhi opened this issue Jul 22, 2020 · 2 comments
Labels
Java Task in language Java

Comments

@pointhi
Copy link

pointhi commented Jul 22, 2020

Creation of a StringBuilder with an input string of size Integer.MAX_INT-15 will cause an NegativeArraySizeException during construction:

String arg = Verifier.nondetString();
if (arg.length() < 1)
return;
StringBuilder buffer1 = new StringBuilder();
StringBuilder buffer2 = new StringBuilder(10);
StringBuilder buffer3 = new StringBuilder(arg);

Looking into the library the constructors are defined as follows:

    public StringBuilder(String str) {
        super(str.length() + 16);
        append(str);
    }
    AbstractStringBuilder(int capacity) {
        value = new char[capacity];
    }

The term of str.length() + 16 is not some implementation specific detail, but is defined in the Java documentation:

https://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html#StringBuilder-java.lang.String-

Constructs a string builder initialized to the contents of the specified string. The initial capacity of the string builder is 16 plus the length of the string argument.

@pointhi
Copy link
Author

pointhi commented Jul 22, 2020

Likely related to #884

@mmuesly
Copy link
Contributor

mmuesly commented Jul 22, 2020

As said for #1096, given the current rule set this does not classify as violation_witness as it is not an assertion violation. We might add the NegativeArraySizeException to the property definition in the future.

@PhilippWendler PhilippWendler added the Java Task in language Java label Jul 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Java Task in language Java
Development

No branches or pull requests

3 participants