Skip to content

Commit 990cfd9

Browse files
committed
Handle exception when ByteBuf is converted to String
1 parent 8886fd0 commit 990cfd9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferLimitException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ public DataBufferLimitException(String message) {
3535
super(message);
3636
}
3737

38+
public DataBufferLimitException(String message, Throwable cause) {
39+
super(message, cause);
40+
}
41+
3842
}

spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,12 @@ public int hashCode() {
374374

375375
@Override
376376
public String toString() {
377-
return this.byteBuf.toString();
377+
try {
378+
return this.byteBuf.toString();
379+
}
380+
catch (OutOfMemoryError ex) {
381+
throw new DataBufferLimitException("Failed to convert data buffer to string: " + ex.getMessage(), ex);
382+
}
378383
}
379384

380385

0 commit comments

Comments
 (0)