Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,12 @@ public synchronized void enqueueSyncPacket(PacketEvent syncPacket, AsyncMarker a

@Override
public Set<PacketType> getReceivingTypes() {
return serverProcessingQueue.keySet();
return clientProcessingQueue.keySet();
}

@Override
public Set<PacketType> getSendingTypes() {
return clientProcessingQueue.keySet();
return serverProcessingQueue.keySet();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mapping correction is right, but no existing test distinguishes the old inverted behavior. Please add a regression test with a sending-only whitelist and assert that its type appears in getSendingTypes() and not getReceivingTypes().

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,18 @@ public PacketSendingQueue getSendingQueue(PacketEvent packet) {
* @return The server or client sending queue the packet belongs to.
*/
public PacketSendingQueue getSendingQueue(PacketEvent packet, boolean createNew) {
QueueContainer queues = playerSendingQueues.get(packet.getPlayer());
Player player = packet.getPlayer();
if (player == null)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not cover the reported login/status failure: those events normally have a non-null TemporaryPlayer. The remaining reachable NPE is when ConcurrentPlayerMap.cachePlayerKey derives a null address and inserts it into the Guava cache. Please guard the derived key there. Keeping the local player variable is still useful because it removes the weak-reference TOCTOU between the lookup and putIfAbsent.

return null;

QueueContainer queues = playerSendingQueues.get(player);

// Safe concurrent initialization
if (queues == null && createNew) {
final QueueContainer newContainer = new QueueContainer();

// Attempt to map the queue
queues = playerSendingQueues.putIfAbsent(packet.getPlayer(), newContainer);
queues = playerSendingQueues.putIfAbsent(player, newContainer);

if (queues == null) {
queues = newContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public T put(int key, T value) {
* @return The old associated value, or NULL.
*/
public T remove(int key) {
if (key < 0 || key >= array.length) return null;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add regression coverage for negative and oversized keys, asserting remove() returns null and leaves size() unchanged. There currently are no IntegerMap.remove() bounds tests, so this can regress without detection.

T old = array[key];
array[key] = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,9 @@ public void serializeItemStack(DataOutputStream output, ItemStack stack) throws

public byte[] getBytesAndRelease(ByteBuf buf) {
try {
if (buf.hasArray()) {
// heap buffer, we can access the array directly
return buf.array();
} else {
// direct buffer, we need to copy the bytes into an array
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
return bytes;
}
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readBytes advances the caller's readerIndex, while the previous heap-buffer path left it unchanged. Since this is a public method, that is an observable compatibility change for callers that retain/reuse the buffer. Could we use ByteBufUtil.getBytes(buf) instead? It returns the exact readable bytes, handles direct buffers and array offsets, and preserves the indices. Please also add a regression assertion for both exact output length and unchanged readerIndex.

return bytes;
} finally {
ReferenceCountUtil.safeRelease(buf);
}
Expand Down
Loading