解决刷新SwaggerUi控制台报错


一、问题描述
在浏览器刷新SwaggerUI的页面,控制台就报错:


java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_291]
    at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_291]
    at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_291]
    at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) ~[swagger-models-1.5.20.jar:1.5.20]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_291]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_291]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_291]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_291]
    
    ......



2021-08-06 14:43:07.757  WARN 23020 --- [nio-8555-exec-5] i.s.m.p.AbstractSerializableParameter    : Illegal DefaultValue null for parameter type integer


java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_291]
    at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_291]
    at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_291]
    at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) ~[swagger-models-1.5.20.jar:1.5.20]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_291]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_291]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_291]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_291]
    
    ......

二、解决办法
在pom中增加依赖



    io.springfox
    springfox-swagger2
    2.9.2


    io.springfox
    springfox-swagger-ui
    2.9.2





    io.swagger
    swagger-annotations
    1.5.22



    io.swagger
    swagger-models
    1.5.22

三、原因
官方代码中存在bug,对于 string 仅判断是否为null 未判断是否为空字符串,导致在将空字串赋值给 int 的时候报错了。