From 3ef00eaa0626489324fcd8c40466674058097605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E6=97=A0=E4=B8=A4=E4=B8=B6?= <442367943@qq.com> Date: Fri, 27 Sep 2019 03:53:35 +0800 Subject: [PATCH] Double check `size` to avoid `ArrayIndexOutOfBoundsException` (#9609) Motivation: Recycler$Stack.pop will occurs `ArrayIndexOutOfBoundsException` in some race cases, we should double check `size` even after `scavenge` called. Modifications: Double check `size` after `scavenge` Result: avoid ArrayIndexOutOfBoundsException in `pop` --- common/src/main/java/io/netty/util/Recycler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/main/java/io/netty/util/Recycler.java b/common/src/main/java/io/netty/util/Recycler.java index 9412424868..814d8e2109 100644 --- a/common/src/main/java/io/netty/util/Recycler.java +++ b/common/src/main/java/io/netty/util/Recycler.java @@ -511,6 +511,10 @@ public abstract class Recycler { return null; } size = this.size; + if (size <= 0) { + // double check, avoid races + return null; + } } size --; DefaultHandle ret = elements[size];