Skip to content

Commit db037e4

Browse files
committed
Revised assertions in StompHeaderAccessor
Issue: SPR-14625 (cherry picked from commit c2feedb)
1 parent 3811a59 commit db037e4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
2929
import org.springframework.messaging.simp.SimpMessageType;
3030
import org.springframework.messaging.support.MessageHeaderAccessor;
31-
import org.springframework.util.Assert;
31+
import org.springframework.util.ClassUtils;
3232
import org.springframework.util.MimeType;
3333
import org.springframework.util.MimeTypeUtils;
3434
import org.springframework.util.StringUtils;
@@ -185,7 +185,9 @@ Map<String, List<String>> getNativeHeaders() {
185185
}
186186

187187
public StompCommand updateStompCommandAsClientMessage() {
188-
Assert.state(SimpMessageType.MESSAGE.equals(getMessageType()), "Unexpected message type " + getMessage());
188+
if (getMessageType() != SimpMessageType.MESSAGE) {
189+
throw new IllegalStateException("Unexpected message type " + getMessageType());
190+
}
189191
if (getCommand() == null) {
190192
setHeader(COMMAND_HEADER, StompCommand.SEND);
191193
}
@@ -196,7 +198,9 @@ else if (!getCommand().equals(StompCommand.SEND)) {
196198
}
197199

198200
public void updateStompCommandAsServerMessage() {
199-
Assert.state(SimpMessageType.MESSAGE.equals(getMessageType()), "Unexpected message type " + getMessage());
201+
if (getMessageType() != SimpMessageType.MESSAGE) {
202+
throw new IllegalStateException("Unexpected message type " + getMessageType());
203+
}
200204
StompCommand command = getCommand();
201205
if ((command == null) || StompCommand.SEND.equals(command)) {
202206
setHeader(COMMAND_HEADER, StompCommand.MESSAGE);
@@ -434,7 +438,10 @@ private String appendSession() {
434438
}
435439

436440
private String appendPayload(Object payload) {
437-
Assert.isInstanceOf(byte[].class, payload);
441+
if (payload.getClass() != byte[].class) {
442+
throw new IllegalStateException(
443+
"Expected byte array payload but got: " + ClassUtils.getQualifiedName(payload.getClass()));
444+
}
438445
byte[] bytes = (byte[]) payload;
439446
String contentType = (getContentType() != null ? " " + getContentType().toString() : "");
440447
if (bytes.length == 0 || getContentType() == null || !isReadableContentType()) {

0 commit comments

Comments
 (0)