Skip to content

java.lang.NumberFormatException: For input string: "" #3069

Closed

Description

@ralf0131
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.0
  • Operating System version: Mac OS
  • Java version: Java 8

Steps to reproduce this issue

run the following UT

    @Test
    public void testConvertPrimitive() {
        Object result = ClassHelper.convertPrimitive(Integer.class, "");
    }

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

No exception is thrown.

Actual Result

Following exception is thrown:

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)

Improvement

  1. Throwing exception is expensive, return null if input String is null or ""
  2. Add more test cases to this method.

Activity

  1. added
    help wanted
    on Dec 27, 2018
  2. added 3 commits that reference this issue on Dec 27, 2018
    683af85
    cba6642
    c129f1d
  3. added a commit that references this issue on Feb 2, 2019
    c2c9de9
  4. added this to the 2.7.1 milestone on Mar 4, 2019
  5. added a commit that references this issue on Mar 26, 2019
    897b80d
  6. alformd commented on Aug 6, 2019

    @alformd
    2019-08-06 16:26:08.383 [NettyServerWorker-6-13] WARN  com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec |  [DUBBO] Fail to encode response: Response [id=5235576, version=stormjar, status=20, event=false, error=null, result=RpcResult [result=null, exception=null]], send bad_response info instead, cause: For input string: "", dubbo version: 2.6.6, current host: 10.50.1.45
    java.lang.NumberFormatException: For input string: ""
            at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_60]
            at java.lang.Integer.parseInt(Integer.java:592) ~[na:1.8.0_60]
            at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_60]
            at com.alibaba.dubbo.common.Version.parseInt(Version.java:92) ~[dubbo-2.6.6.jar:2.6.6]
            at com.alibaba.dubbo.common.Version.getIntVersion(Version.java:81) ~[dubbo-2.6.6.jar:2.6.6]
            at com.alibaba.dubbo.common.Version.isSupportResponseAttatchment(Version.java:70) ~[dubbo-2.6.6.jar:2.6.6]
            at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCodec.encodeResponseData(DubboCodec.java:192) ~[dubbo-2.6.6.jar:2.6.6]
            at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.encodeResponse(ExchangeCodec.java:278) [dubbo-2.6.6.jar:2.6.6]
            at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:74) [dubbo-2.6.6.jar:2.6.6]
            at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:38) [dubbo-2.6.6.jar:2.6.6]
            at com.alibaba.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalEncoder.encode(NettyCodecAdapter.java:70) [dubbo-2.6.6.jar:2.6.6]
            at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:743) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:735) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:820) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:728) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.ChannelDuplexHandler.write(ChannelDuplexHandler.java:106) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at com.alibaba.dubbo.remoting.transport.netty4.NettyServerHandler.write(NettyServerHandler.java:105) [dubbo-2.6.6.jar:2.6.6]
            at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:743) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:735) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext.access$1900(AbstractChannelHandlerContext.java:36) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.write(AbstractChannelHandlerContext.java:1072) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:1126) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:1061) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:408) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:455) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) [netty-all-4.0.42.Final.jar:4.0.42.Final]
            at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
    
  7. ralf0131 commented on Aug 6, 2019

    @ralf0131
    ContributorAuthor

    It's already been fixed, please try 2.7.4-SNAPSHOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions