2016-04-24 74 views
-1

Map<String, User> map = users.stream().collect(Collectors.toMap(User::getUsername, e -> e)); 代碼正常運行,但很長一段時間沒有任何操作,然後路由到此代碼將使後續錯誤。java8新增功能彈簧錯誤

請幫幫我!!!

2016-04-24 17:51:56.262 ERROR 8343 --- [nio-8081-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: java.lang.NullPointerException] with root cause 

java.lang.NullPointerException: null 
    at org.springsource.loaded.support.Java8.callLambdaMetaFactory(Java8.java:153) 
    at org.springsource.loaded.support.Java8.emulateInvokeDynamic(Java8.java:88) 
    at org.springsource.loaded.TypeRegistry.idyrun(TypeRegistry.java:1787) 
    at crazy.action.ExcelAction.createEntryExcel(ExcelAction.java:86) 
    at crazy.action.ExcelAction.get(ExcelAction.java:62) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 

回答

0
User::getUsername 

將調用user.getUsername()。看起來您的地圖中有一個值(用戶)爲空的條目,這會導致顯示的異常。

+0

我可以確保用戶不爲空。在網絡系統中,一旦獲取url,該方法是正常的,bug長時間沒有操作,該方法會拋出異常。 – hard