Skip to content

NPE if the ApiResponseObject is missing #75

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

Closed
jameselsey opened this issue Jan 21, 2015 · 4 comments
Closed

NPE if the ApiResponseObject is missing #75

jameselsey opened this issue Jan 21, 2015 · 4 comments
Assignees
Labels
Milestone

Comments

@jameselsey
Copy link

If you forget to add the ApiResponseObject to a controller method, you'll get a javascript alert on the jsondoc-ui and will see this in the log:

java.lang.NullPointerException
    org.jsondoc.springmvc.scanner.SpringJSONDocScanner.getApiResponseObject(SpringJSONDocScanner.java:116)
    org.jsondoc.springmvc.scanner.SpringJSONDocScanner.mergeApiMethodDoc(SpringJSONDocScanner.java:52)
    org.jsondoc.core.util.AbstractJSONDocScanner.getApiMethodDoc(AbstractJSONDocScanner.java:143)
    org.jsondoc.core.util.AbstractJSONDocScanner.getApiMethodDocs(AbstractJSONDocScanner.java:122)
    org.jsondoc.core.util.AbstractJSONDocScanner.getApiDoc(AbstractJSONDocScanner.java:110)
    org.jsondoc.core.util.AbstractJSONDocScanner.getApiDocs(AbstractJSONDocScanner.java:93)
    org.jsondoc.core.util.AbstractJSONDocScanner.getApiDocsMap(AbstractJSONDocScanner.java:315)
    org.jsondoc.core.util.AbstractJSONDocScanner.getJSONDoc(AbstractJSONDocScanner.java:80)
    org.jsondoc.springmvc.controller.JSONDocController.getApi(JSONDocController.java:32)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

The offending method is

private ApiResponseObjectDoc getApiResponseObject(Method method, ApiResponseObjectDoc apiResponseObjectDoc) {
        if(method.getReturnType().isAssignableFrom(ResponseEntity.class)) {
            apiResponseObjectDoc.getJsondocType().getType().remove(0);
        }

        return apiResponseObjectDoc;
    }

It would be best to null check the response object and display this in another way, as it's not obvious unless you check logs then debug to find which method is missing the annotation (if you have lots, like I do)

@fabiomaffioletti
Copy link
Owner

Thank you, I'll look into it

@fabiomaffioletti fabiomaffioletti self-assigned this Jan 21, 2015
@fabiomaffioletti fabiomaffioletti added this to the 1.1.3 milestone Jan 21, 2015
@fabiomaffioletti
Copy link
Owner

Not able to reproduce. Please give some more info or share code snippets.

@fabiomaffioletti fabiomaffioletti modified the milestones: 1.1.3, 1.1.4 Jan 21, 2015
@jameselsey
Copy link
Author

Create a controller, annotate it with Api

Create some controller methods, annotate those with ApiMethod and ApiResponseObject

Pick one controller and remove the ApiResponseObject annotation

Try to view the jsondoc ui, you should get a js alert box and a 500 in the js console

@fabiomaffioletti
Copy link
Owner

Still not able to reproduce. I created a temporary controller in the demo project (http://jsondoc.eu01.aws.af.cm/jsondoc.jsp) to show that even if you don't specify the annotation, everything still works. Take a look at the code here https://github.com/fabiomaffioletti/jsondoc-samples/blob/master/jsondoc-sample-springmvc/src/main/java/org/jsondoc/sample/controller/JamesController.java and browse the documentation on the demo website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants