Skip to content

Commit 86bfbe6

Browse files
author
xinqiu.hu
committed
retrun -1 when tgt has remaining and src expired first in Text.find
1 parent 52c2d99 commit 86bfbe6

File tree

2 files changed

+4
-4
lines changed
  • hadoop-common-project/hadoop-common/src

2 files changed

+4
-4
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/Text.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,9 @@ public int find(String what, int start) {
199199
int pos = src.position()-1;
200200
while (tgt.hasRemaining()) {
201201
if (!src.hasRemaining()) { // src expired first
202-
tgt.reset();
203-
src.reset();
204-
found = false;
205-
break;
202+
// the remaining bytes in src will always smaller than tgt,
203+
// so we can return -1 directory
204+
return -1;
206205
}
207206
if (!(tgt.get() == src.get())) {
208207
tgt.reset();

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestText.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public void testFind() throws Exception {
238238
assertThat(text.find("ac")).isEqualTo(-1);
239239
assertThat(text.find("\u20ac")).isEqualTo(4);
240240
assertThat(text.find("\u20ac", 5)).isEqualTo(11);
241+
assertThat(text.find("cd\u20acq")).isEqualTo(-1);
241242
}
242243

243244
@Test

0 commit comments

Comments
 (0)