Skip to content

Add missing bounds check to deleteCharAt - #15979

Merged
keithc-ca merged 1 commit into
eclipse-openj9:masterfrom
mikezhang1234567890:string
Sep 27, 2022
Merged

Add missing bounds check to deleteCharAt#15979
keithc-ca merged 1 commit into
eclipse-openj9:masterfrom
mikezhang1234567890:string

Conversation

@mikezhang1234567890

@mikezhang1234567890 mikezhang1234567890 commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

For StringBuilder and StringBuffer
Add tests for deleteCharAt with out of bound indices.

Fixes #15897

Tested internally here running JCL_Test_SE80

@pshipton

Copy link
Copy Markdown
Member

jenkins test sanity,extended,sanity.openjdk alinux64 jdk8

Comment thread jcl/src/java.base/share/classes/java/lang/StringBuffer.java Outdated
@keithc-ca

Copy link
Copy Markdown
Contributor

delete(int start, int end) doesn't appear to match its documented behavior; perhaps all that is needed (e.g. in StringBuffer) is to remove this:

    if (end > currentLength) {
        end = currentLength;
    }

@mikezhang1234567890

mikezhang1234567890 commented Sep 27, 2022

Copy link
Copy Markdown
Contributor Author

In this case, I think our doc is wrong, last condition to throw the exception should be start > length() instead of end > length().

@pshipton

Copy link
Copy Markdown
Member

@keithc-ca

Copy link
Copy Markdown
Contributor

In this case, I think our doc is wrong, last condition to throw the exception should be start > length() instead of end > length().

I think the documentation is correct. It might be better written as three {@code} blocks instead of two.

For StringBuilder and StringBuffer
Add tests for deleteCharAt with out of bound indices.

Signed-off-by: Mike Zhang <mike.h.zhang@ibm.com>
@mikezhang1234567890

Copy link
Copy Markdown
Contributor Author

Updated the docs for delete as well to hopefully make things clearer. Can you take another look please @keithc-ca ?

@keithc-ca

Copy link
Copy Markdown
Contributor

jenkins test sanity alinux64 jdk8

@pshipton

pshipton commented Sep 27, 2022

Copy link
Copy Markdown
Member

I'm inclined to include this in the 0.35 release since it fixes a bug / user problem, the fix appears low risk, and we haven't yet done the M2 build for jdk8. @keithc-ca thoughts?

@keithc-ca

Copy link
Copy Markdown
Contributor

I'm inclined to include this in the 0.35 release since it fixes a bug / user problem, the fix appears low risk, and we haven't yet done the M2 build for jdk8.

I agree.

@pshipton

Copy link
Copy Markdown
Member

@mikezhang1234567890 please create a PR against the 0.35 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenJ9 (JDK8) fails to throw the StringIndexOutOfBoundsException when calling function StringBuilder deleteCharAt (int index)

3 participants