<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.0+</li>
<li>Operating System version: mac</li>
<li>Java version: 1.8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto">start telnet and user select,like this</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/15943801/73730337-8ff07b00-4771-11ea-9fd7-d2363f65b145.png"><img src="https://user-images.githubusercontent.com/15943801/73730337-8ff07b00-4771-11ea-9fd7-d2363f65b145.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">When selct 1,I hope choose <code class="notranslate">hello(HelloRequest)</code>,but Dubbo choose <code class="notranslate">hello(HelloRequestV2)</code>.</p>
<p dir="auto">When select 2,Dubbo has some error!</p>
<p dir="auto">This bug is caused by <code class="notranslate">methodList.get(Integer.parseInt(message))</code> in SelectTelnetHandler。</p>
<p dir="auto">Select should use 1~2 ,But methodList use 0-1！</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    public String telnet(Channel channel, String message) {
        if (message == null || message.length() == 0) {
            return &quot;Please input the index of the method you want to invoke, eg: \r\n select 1&quot;;
        }
        List&lt;Method&gt; methodList = (List&lt;Method&gt;) channel.getAttribute(InvokeTelnetHandler.INVOKE_METHOD_LIST_KEY);
        if (CollectionUtils.isEmpty(methodList)) {
            return &quot;Please use the invoke command first.&quot;;
        }
        if (!StringUtils.isInteger(message) || Integer.parseInt(message) &lt; 1 || Integer.parseInt(message) &gt; methodList.size()) {
            return &quot;Illegal index ,please input select 1~&quot; + methodList.size();
        }
        Method method = methodList.get(Integer.parseInt(message));
        channel.setAttribute(SELECT_METHOD_KEY, method);
        channel.setAttribute(SELECT_KEY, Boolean.TRUE);
        String invokeMessage = (String) channel.getAttribute(InvokeTelnetHandler.INVOKE_MESSAGE_KEY);
        return invokeTelnetHandler.telnet(channel, invokeMessage);
    }"><pre class="notranslate">    <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-s1">telnet</span>(<span class="pl-smi">Channel</span> <span class="pl-s1">channel</span>, <span class="pl-smi">String</span> <span class="pl-s1">message</span>) {
        <span class="pl-k">if</span> (<span class="pl-s1">message</span> == <span class="pl-c1">null</span> || <span class="pl-s1">message</span>.<span class="pl-en">length</span>() == <span class="pl-c1">0</span>) {
            <span class="pl-k">return</span> <span class="pl-s">"Please input the index of the method you want to invoke, eg: <span class="pl-s">\r</span><span class="pl-s">\n</span> select 1"</span>;
        }
        <span class="pl-smi">List</span>&lt;<span class="pl-smi">Method</span>&gt; <span class="pl-s1">methodList</span> = (<span class="pl-smi">List</span>&lt;<span class="pl-smi">Method</span>&gt;) <span class="pl-s1">channel</span>.<span class="pl-en">getAttribute</span>(<span class="pl-smi">InvokeTelnetHandler</span>.<span class="pl-c1">INVOKE_METHOD_LIST_KEY</span>);
        <span class="pl-k">if</span> (<span class="pl-smi">CollectionUtils</span>.<span class="pl-en">isEmpty</span>(<span class="pl-s1">methodList</span>)) {
            <span class="pl-k">return</span> <span class="pl-s">"Please use the invoke command first."</span>;
        }
        <span class="pl-k">if</span> (!<span class="pl-smi">StringUtils</span>.<span class="pl-en">isInteger</span>(<span class="pl-s1">message</span>) || <span class="pl-smi">Integer</span>.<span class="pl-en">parseInt</span>(<span class="pl-s1">message</span>) &lt; <span class="pl-c1">1</span> || <span class="pl-smi">Integer</span>.<span class="pl-en">parseInt</span>(<span class="pl-s1">message</span>) &gt; <span class="pl-s1">methodList</span>.<span class="pl-en">size</span>()) {
            <span class="pl-k">return</span> <span class="pl-s">"Illegal index ,please input select 1~"</span> + <span class="pl-s1">methodList</span>.<span class="pl-en">size</span>();
        }
        <span class="pl-smi">Method</span> <span class="pl-s1">method</span> = <span class="pl-s1">methodList</span>.<span class="pl-en">get</span>(<span class="pl-smi">Integer</span>.<span class="pl-en">parseInt</span>(<span class="pl-s1">message</span>));
        <span class="pl-s1">channel</span>.<span class="pl-en">setAttribute</span>(<span class="pl-c1">SELECT_METHOD_KEY</span>, <span class="pl-s1">method</span>);
        <span class="pl-s1">channel</span>.<span class="pl-en">setAttribute</span>(<span class="pl-c1">SELECT_KEY</span>, <span class="pl-smi">Boolean</span>.<span class="pl-c1">TRUE</span>);
        <span class="pl-smi">String</span> <span class="pl-s1">invokeMessage</span> = (<span class="pl-smi">String</span>) <span class="pl-s1">channel</span>.<span class="pl-en">getAttribute</span>(<span class="pl-smi">InvokeTelnetHandler</span>.<span class="pl-c1">INVOKE_MESSAGE_KEY</span>);
        <span class="pl-k">return</span> <span class="pl-s1">invokeTelnetHandler</span>.<span class="pl-en">telnet</span>(<span class="pl-s1">channel</span>, <span class="pl-s1">invokeMessage</span>);
    }</pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.6-snapshot</li>
</ul>
<p dir="auto">files:<br>
<a href="https://github.com/apache/dubbo/blob/master/dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java#L91">https://github.com/apache/dubbo/blob/master/dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java#L91</a><br>
<a href="https://github.com/apache/dubbo/blob/master/dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java#L99">https://github.com/apache/dubbo/blob/master/dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java#L99</a></p>
<p dir="auto">This check is useless, invocation cannot be null here, since new RmiRemoteInvocation(...) always is non-null.</p>