/*
 * Copyright 2014 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.handler.ipfilter;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.internal.ObjectUtil;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

/**
 * This class allows one to filter new {@link Channel}s based on the
 * {@link IpFilterRule}s passed to its constructor. If no rules are provided, all connections
 * will be accepted.
 *
 * If you would like to explicitly take action on rejected {@link Channel}s, you should override
 * {@link AbstractRemoteAddressFilter#channelRejected(ChannelHandlerContext, SocketAddress)}.
 */
@Sharable
public class RuleBasedIpFilter extends AbstractRemoteAddressFilter<InetSocketAddress> {

    private final IpFilterRule[] rules;

    public RuleBasedIpFilter(IpFilterRule... rules) {
        this.rules = ObjectUtil.checkNotNull(rules, "rules");
    }

    @Override
    protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception {
        for (IpFilterRule rule : rules) {
            if (rule == null) {
                break;
            }

            if (rule.matches(remoteAddress)) {
                return rule.ruleType() == IpFilterRuleType.ACCEPT;
            }
        }

        return true;
    }
}

@@ -906,12 +906,70 @@
 ss;%0A
-%0A/**
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * %3Cp%3E
 %0A * 
@@ -1151,16 +1151,31 @@
 pted.%0A *
+ %3C/p%3E%0A *%0A * %3Cp%3E
 %0A * If y
@@ -1358,16 +1358,148 @@
 ress)%7D.%0A
+ * %3C/p%3E%0A *%0A * %3Cp%3E Consider using %7B@link IpSubnetFilter%7D for better performance while not as%0A * general purpose as this filter. %3C/p%3E%0A
  */%0A@Sha
@@ -1611,16 +1611,65 @@
 e final 
+boolean acceptIfNotFound;%0A    private final List%3C
 IpFilter
@@ -1676,10 +1676,9 @@
 Rule
-%5B%5D
+%3E
  rul
@@ -1690,119 +1690,1203 @@
     
-public RuleBasedIpFilter(IpFilterRule... rules) %7B%0A        this.rules = ObjectUtil.checkNotNull(rules, %22rules%22);
+/**%0A     * %3Cp%3E Create new Instance of %7B@link RuleBasedIpFilter%7D and filter incoming connections%0A     * based on their IP address and %7B@code rules%7D applied. %3C/p%3E%0A     *%0A     * %3Cp%3E %7B@code acceptIfNotFound%7D is set to %7B@code true%7D. %3C/p%3E%0A     *%0A     * @param rules An array of %7B@link IpFilterRule%7D containing all rules.%0A     */%0A    public RuleBasedIpFilter(IpFilterRule... rules) %7B%0A        this(true, rules);%0A    %7D%0A%0A    /**%0A     * Create new Instance of %7B@link RuleBasedIpFilter%7D and filter incoming connections%0A     * based on their IP address and %7B@code rules%7D applied.%0A     *%0A     * @param acceptIfNotFound If %7B@code true%7D then accept connection from IP Address if it%0A     *                         doesn't match any rule.%0A     * @param rules            An array of %7B@link IpFilterRule%7D containing all rules.%0A     */%0A    public RuleBasedIpFilter(boolean acceptIfNotFound, IpFilterRule... rules) %7B%0A        ObjectUtil.checkNotNull(rules, %22rules%22);%0A%0A        this.acceptIfNotFound = acceptIfNotFound;%0A        this.rules = new ArrayList%3CIpFilterRule%3E(rules.length);%0A%0A        for (IpFilterRule rule : rules) %7B%0A            if (rule != null) %7B%0A                this.rules.add(rule);%0A            %7D%0A        %7D
 %0A   
@@ -3057,78 +3057,8 @@
 ) %7B%0A
-            if (rule == null) %7B%0A                break;%0A            %7D%0A%0A
     
@@ -3207,20 +3207,32 @@
  return 
-true
+acceptIfNotFound
 ;%0A    %7D%0A

Add `null` rule check in `rules` array of RuleBasedIpFilter (#10527)