<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/incubator-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/incubator-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 OS</li>
<li>Java version: Java 8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto">run the following UT</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    @Test
    public void testConvertPrimitive() {
        Object result = ClassHelper.convertPrimitive(Integer.class, &quot;&quot;);
    }"><pre class="notranslate">    <span class="pl-c1">@</span><span class="pl-c1">Test</span>
    <span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-s1">testConvertPrimitive</span>() {
        <span class="pl-smi">Object</span> <span class="pl-s1">result</span> = <span class="pl-smi">ClassHelper</span>.<span class="pl-en">convertPrimitive</span>(<span class="pl-smi">Integer</span>.<span class="pl-k">class</span>, <span class="pl-s">""</span>);
    }</pre></div>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.</p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">No exception is thrown.</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">Following exception is thrown:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="java.lang.NumberFormatException: For input string: &quot;&quot;

	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.base/java.lang.Integer.parseInt(Integer.java:662)
	at java.base/java.lang.Integer.valueOf(Integer.java:983)
	at org.apache.dubbo.common.utils.ClassHelper.convertPrimitive(ClassHelper.java:277)
	at org.apache.dubbo.common.utils.ClassHelperTest.testConvertPrimitive(ClassHelperTest.java:125)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)"><pre class="notranslate"><code class="notranslate">java.lang.NumberFormatException: For input string: ""

	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.base/java.lang.Integer.parseInt(Integer.java:662)
	at java.base/java.lang.Integer.valueOf(Integer.java:983)
	at org.apache.dubbo.common.utils.ClassHelper.convertPrimitive(ClassHelper.java:277)
	at org.apache.dubbo.common.utils.ClassHelperTest.testConvertPrimitive(ClassHelperTest.java:125)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
</code></pre></div>
<h3 dir="auto">Improvement</h3>
<ol dir="auto">
<li>Throwing exception is expensive, return null if input String is null or ""</li>
<li>Add more test cases to this method.</li>
</ol>
<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/incubator-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/incubator-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.2-SNAPSHOT</li>
<li>Operating System version: OS X 10.14.4</li>
<li>Java version: 1.8.0_202</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>[DUBBO] Serialization extension org.apache.dubbo.common.serialize.protostuff.ProtostuffSerialization has duplicate id to Serialization extension org.apache.dubbo.common.serialize.avro.AvroSerialization, ignore this Serialization extension</li>
</ol>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="CodecSupport
static {
        Set&lt;String&gt; supportedExtensions = ExtensionLoader.getExtensionLoader(Serialization.class).getSupportedExtensions();
        for (String name : supportedExtensions) {
            Serialization serialization = ExtensionLoader.getExtensionLoader(Serialization.class).getExtension(name);
            byte idByte = serialization.getContentTypeId();
            if (ID_SERIALIZATION_MAP.containsKey(idByte)) {
                logger.error(&quot;Serialization extension &quot; + serialization.getClass().getName()
                        + &quot; has duplicate id to Serialization extension &quot;
                        + ID_SERIALIZATION_MAP.get(idByte).getClass().getName()
                        + &quot;, ignore this Serialization extension&quot;);
                continue;
            }
            ID_SERIALIZATION_MAP.put(idByte, serialization);
            ID_SERIALIZATIONNAME_MAP.put(idByte, name);
        }
    }

public class ProtostuffSerialization implements Serialization {
    @Override
    public byte getContentTypeId() {
        return 10;
    }
}

public class AvroSerialization implements Serialization {
    @Override
    public byte getContentTypeId() {
        return 10;
    }
}"><pre class="notranslate"><span class="pl-smi">CodecSupport</span>
<span class="pl-s1">static</span> {
        <span class="pl-smi">Set</span>&lt;<span class="pl-smi">String</span>&gt; <span class="pl-s1">supportedExtensions</span> = <span class="pl-smi">ExtensionLoader</span>.<span class="pl-en">getExtensionLoader</span>(<span class="pl-smi">Serialization</span>.<span class="pl-k">class</span>).<span class="pl-en">getSupportedExtensions</span>();
        <span class="pl-k">for</span> (<span class="pl-smi">String</span> <span class="pl-s1">name</span> : <span class="pl-s1">supportedExtensions</span>) {
            <span class="pl-smi">Serialization</span> <span class="pl-s1">serialization</span> = <span class="pl-smi">ExtensionLoader</span>.<span class="pl-en">getExtensionLoader</span>(<span class="pl-smi">Serialization</span>.<span class="pl-k">class</span>).<span class="pl-en">getExtension</span>(<span class="pl-s1">name</span>);
            <span class="pl-smi">byte</span> <span class="pl-s1">idByte</span> = <span class="pl-s1">serialization</span>.<span class="pl-en">getContentTypeId</span>();
            <span class="pl-k">if</span> (<span class="pl-smi">ID_SERIALIZATION_MAP</span>.<span class="pl-en">containsKey</span>(<span class="pl-s1">idByte</span>)) {
                <span class="pl-s1">logger</span>.<span class="pl-en">error</span>(<span class="pl-s">"Serialization extension "</span> + <span class="pl-s1">serialization</span>.<span class="pl-en">getClass</span>().<span class="pl-en">getName</span>()
                        + <span class="pl-s">" has duplicate id to Serialization extension "</span>
                        + <span class="pl-smi">ID_SERIALIZATION_MAP</span>.<span class="pl-en">get</span>(<span class="pl-s1">idByte</span>).<span class="pl-en">getClass</span>().<span class="pl-en">getName</span>()
                        + <span class="pl-s">", ignore this Serialization extension"</span>);
                <span class="pl-k">continue</span>;
            }
            <span class="pl-smi">ID_SERIALIZATION_MAP</span>.<span class="pl-en">put</span>(<span class="pl-s1">idByte</span>, <span class="pl-s1">serialization</span>);
            <span class="pl-smi">ID_SERIALIZATIONNAME_MAP</span>.<span class="pl-en">put</span>(<span class="pl-s1">idByte</span>, <span class="pl-s1">name</span>);
        }
    }

<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">ProtostuffSerialization</span> <span class="pl-k">implements</span> <span class="pl-smi">Serialization</span> {
    <span class="pl-c1">@</span><span class="pl-c1">Override</span>
    <span class="pl-k">public</span> <span class="pl-smi">byte</span> <span class="pl-en">getContentTypeId</span>() {
        <span class="pl-k">return</span> <span class="pl-c1">10</span>;
    }
}

<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">AvroSerialization</span> <span class="pl-k">implements</span> <span class="pl-smi">Serialization</span> {
    <span class="pl-c1">@</span><span class="pl-c1">Override</span>
    <span class="pl-k">public</span> <span class="pl-smi">byte</span> <span class="pl-en">getContentTypeId</span>() {
        <span class="pl-k">return</span> <span class="pl-c1">10</span>;
    }
}</pre></div>