Error background
Java code occasionally reports an error, but it will not report an error under normal circumstances.
Error
exception: java.lang.reflect.InvocationTargetException: null
2020-05-11 at 15:17:39 CST traceId:[] ERROR io.netty.util.internal.logging.AbstractInternalLogger 91 error-Unexpected exception: java.lang.reflect.InvocationTargetException: null at sun.reflect.GeneratedMethodAccessor214. invoke(Unknown Source) ~[?:? ] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 43) ~[?:1.8 .0_192] at java.lang.reflect.Method.invoke(Method.java: 498) ~[?:1.8 .0_192] at org.yeauty.pojo.PojoEndpointServer.doOnClose(PojoEndpointServer.java: 121) [netty-websocket-spring-boot-starter-0.8.0.jar!/:? ] at org.yeauty.standard.WebSocketServerHandler.channelInactive(WebSocketServerHandler.java: 29) [netty-websocket-spring-boot-starter-0.8.0.jar!/:? ] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 257) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 243) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java: 236) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java: 393) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java: 358) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 257) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 243) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java: 236) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java: 1416) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 257) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 243) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java: 912) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.AbstractChannel$AbstractUnsafe$ 8.run(AbstractChannel.java:816) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java: 163) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java: 416) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java: 515) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.util.concurrent.SingleThreadEventExecutor$ 5.run(SingleThreadEventExecutor.java:918) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.util.internal.ThreadExecutorMap$ 2.run(ThreadExecutorMap.java:74) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java: 30) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final] at java.lang.Thread.run(Thread.java: 748) [?:1.8 .0_192] Caused by: java.util.ConcurrentModificationException at java.util.HashMap$HashIterator.nextNode(HashMap.java: 1445) ~[?:1.8 .0_192] at java.util.HashMap$EntryIterator.next(HashMap.java: 1479) ~[?:1.8 .0_192] at java.util.HashMap$EntryIterator.next(HashMap.java: 1477) ~[?:1.8 .0_192] at com.jcdz.hbdservice.websocket.ServerWebSocket1.onClose(ServerWebSocket1.java: 38) ~[coalminehbdservice-1.0.jar!/:1.0 ] ... 25 more
Reason for error
There are many reasons for the error, I will only say the reason I came into contact:
(1) If (==) judgment statement is wrong
if( devMap. getOrDefault ( “locationcode”,”” ) == null )
devMap.get( “locationcode” ) : It is possible that a null is passed, and a null pointer will appear at this time
View the source code of getOrDefault()
1 /** 2 * Returns the value to which the specified key is mapped, or 3 * { @code defaultValue} if this map contains no mapping for the key. 4 * 5 * @implSpec 6 * The default implementation makes no guarantees about synchronization 7 * or atomicity properties of this method. Any implementation providing 8 * atomicity guarantees must override this method and document its 9 * concurrency properties. 10 * 11 * @param key the key whose associated value is to be returned 12 * @param defaultValue the default mapping of the key 13 * @return the value to which the specified key is mapped, or 14 * { @code defaultValue} if this map contains no mapping for the key 15 * @throws ClassCastException if the key AN of inappropriate type for IS 16 * the this Map . 17 * (<a href="{@%20docroot%20}/java/util/Collection.html#optional-restrictions"> optional </a>) 18 is * @throws a NullPointerException IF The specified key is null and this map 19 * does not permit null keys 20 * (<a href="{@%20docRoot%20}/java/util/Collection.html#optional-restrictions">optional</a>) 21 * @since 1.8 22 */ 23 default V getOrDefault (Object key, V defaultValue) { 24 V v; 25 return (((v = get(key)) != null ) || containsKey(key)) 26 ? V 27 : defaultValue; 28 }
@throws NullPointerException if the specified key is null and this map does not allow null keys
We can see that there is a get(key) method in the getOrDefault () method. At this time, if the value of key is a null, an error will be reported, such as key:null.
When the value of map is passed in, it is necessary to avoid the phenomenon of passing in map.put(key: null). You can use map.put(key: “”) instead.
(2) if (equals) judgment statement is wrong
if(! time .equals( “1900-01-01 00:00:00” ))
time : it is possible to pass a null, then there will be a null pointer phenomenon
Error resolution
Modify the sequence of judgment statements as follows:
if( null == devMap . getOrDefault ( “locationcode”,”” ))
if(! “1900-01-01 00:00:00”.equals(time))
Read More:
- [Solved] java.lang.reflect.InaccessibleObjectException: Unable to make protected java.net.http.HttpRequest()…
- Uiautomatorviewer Error: Unexpected error while obtaining UI hierarchy java.lang.reflect.InvocationT…
- JPA @ManyToMany java.lang.StackOverflowError: null [How to Solve]
- [Solved] Springboot Reflection calls ServiceImpl Error: java.lang.NullPointerException, mapper is null
- Hive ERROR Failed with exception java.io.IOException:java.lang.IllegalArgumentException
- POI Export Excel Error: HTTP Status 500 – Request processing failed; nested exception is java.lang.NullPointerException
- NestedServletException, Handler dispatch failed; nested exception is java.lang.StackOverflowError [Solved]
- [Solved] swagger3 Error: org.springframework.context.ApplicationContextException: Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException
- [Solved] Request processing failed; nested exception is java.lang.NullPointerException
- [Solved] Non-fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library “libmmkv.so“ not found
- [Maven Error] Exception in thread “main” java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
- Win assembleDebug Downloading gradle.zip Error: Exception in thread “main” java.lang.RuntimeException: javax.net.ssl.SSLExce
- Java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; error resolution
- [Solved] Hystrix error: java.util.concurrent.TimeoutException: null
- [Solved] Response Export error on submit request on future invoke, java.lang.OutOfMemoryError: Java heap space
- Tomcat startup error: java.lang.NoClassDefFoundError
- Android Working Directory:NULL Environment:NULL Error
- Idea Error: java: java.lang.OutOfMemoryError: GC overhead limit exceeded
- TypeException: Error setting non null for parameter #1 with JdbcType null