Skip to content

Commit f3f691c

Browse files
committed
Revised assertions in StompHeaderAccessor
Issue: SPR-14625
1 parent 56b197b commit f3f691c

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.
@@ -29,7 +29,7 @@
2929
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
3030
import org.springframework.messaging.simp.SimpMessageType;
3131
import org.springframework.messaging.support.MessageHeaderAccessor;
32-
import org.springframework.util.Assert;
32+
import org.springframework.util.ClassUtils;
3333
import org.springframework.util.MimeType;
3434
import org.springframework.util.MimeTypeUtils;
3535
import org.springframework.util.StringUtils;
@@ -186,7 +186,9 @@ Map<String, List<String>> getNativeHeaders() {
186186
}
187187

188188
public StompCommand updateStompCommandAsClientMessage() {
189-
Assert.state(SimpMessageType.MESSAGE.equals(getMessageType()), "Unexpected message type " + getMessage());
189+
if (getMessageType() != SimpMessageType.MESSAGE) {
190+
throw new IllegalStateException("Unexpected message type " + getMessageType());
191+
}
190192
if (getCommand() == null) {
191193
setHeader(COMMAND_HEADER, StompCommand.SEND);
192194
}
@@ -197,7 +199,9 @@ else if (!getCommand().equals(StompCommand.SEND)) {
197199
}
198200

199201
public void updateStompCommandAsServerMessage() {
200-
Assert.state(SimpMessageType.MESSAGE.equals(getMessageType()), "Unexpected message type " + getMessage());
202+
if (getMessageType() != SimpMessageType.MESSAGE) {
203+
throw new IllegalStateException("Unexpected message type " + getMessageType());
204+
}
201205
StompCommand command = getCommand();
202206
if ((command == null) || StompCommand.SEND.equals(command)) {
203207
setHeader(COMMAND_HEADER, StompCommand.MESSAGE);
@@ -435,7 +439,10 @@ private String appendSession() {
435439
}
436440

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

0 commit comments

Comments
 (0)