Skip to content

Commit

Permalink
Merge pull request #16467 from mikezhang1234567890/string
Browse files Browse the repository at this point in the history
Fix String.split when regex is compressed and searched string is not
  • Loading branch information
keithc-ca authored Jan 12, 2023
2 parents b8542b9 + 7251c94 commit cf7d04f
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions jcl/src/java.base/share/classes/java/lang/String.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION < 17]*/
/*******************************************************************************
* Copyright (c) 1998, 2022 IBM Corp. and others
* Copyright (c) 1998, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -3352,9 +3352,16 @@ public String[] split(String regex, int max) {
} else {
int rLength = regex.lengthInternal();

byte[] splitChars = regex.value;
byte[] splitChars;
// if regex is compressed and this string isn't, decompress regex string
if (!compressed && regex.isCompressed()) {
splitChars = new byte[rLength << 1];
decompress(regex.value, 0, splitChars, 0, rLength);
} else {
splitChars = regex.value;
}

char firstChar = charAtInternal(0, regex.value);
char firstChar = charAtInternal(0, splitChars);
while (current < end) {
if (charAtInternal(current, chars) == firstChar) {
int idx = current + 1;
Expand Down Expand Up @@ -7740,9 +7747,16 @@ public String[] split(String regex, int max) {
} else {
int rLength = regex.lengthInternal();

char[] splitChars = regex.value;
char[] splitChars;
// if regex is compressed and this string isn't, decompress regex string
if (!compressed && regex.isCompressed()) {
splitChars = new char[rLength];
decompress(regex.value, 0, splitChars, 0, rLength);
} else {
splitChars = regex.value;
}

char firstChar = charAtInternal(0, regex.value);
char firstChar = charAtInternal(0, splitChars);
while (current < end) {
if (charAtInternal(current, chars) == firstChar) {
int idx = current + 1;
Expand Down

0 comments on commit cf7d04f

Please sign in to comment.