Skip to content

如果JsonInjector.get函数的输入值为null零, 则更改错误消息。 #1613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/org/nutz/mvc/adaptor/injector/JsonInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Type;
import java.util.Map;
import java.util.Objects;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -33,7 +34,7 @@ public Object get( ServletContext sc,
if (null == name)
return Mapl.maplistToObj(refer, type);

Map<String, Object> map = (Map<String, Object>)refer;
Map<String, Object> map = (Map<String, Object>) Objects.requireNonNull(refer, "refer");
Object theObj = map.get(name);
if (null == theObj)
return null;
Expand Down
24 changes: 24 additions & 0 deletions test/org/nutz/mvc/adaptor/injector/JsonInjectorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.nutz.mvc.adaptor.injector;

import static org.junit.Assert.*;

import org.junit.Test;

/**
* @author Heewon Lee ([email protected])
*/
public class JsonInjectorTest {

@Test
public void test_null_refer() {
// 准备数据
JsonInjector inj = new JsonInjector(null, "");

// 检测
Throwable exc = assertThrows(NullPointerException.class, () -> {
inj.get(null, null, null, null);
});
assertEquals("refer", exc.getMessage());
}

}