question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointer exception on mapModel

See original GitHub issue

What version of the library are you using? -> 3.0.0 What kind of issue is this? -> Bug, Regression

When browsing v3/api-docs?group=api I get a Nullpointer Exception in SchemaMapper.java line 97. It seems like the mapFrom function returns null.

java.lang.NullPointerException: null
	at springfox.documentation.oas.mappers.SchemaMapper.model(SchemaMapper.java:97) ~[springfox-oas-3.0.0.jar:3.0.0]
	at springfox.documentation.oas.mappers.SchemaMapper.mapModel(SchemaMapper.java:85) ~[springfox-oas-3.0.0.jar:3.0.0]
	at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapperImpl.fromRepresentation(ServiceModelToOpenApiMapperImpl.java:187) ~[springfox-oas-3.0.0.jar:3.0.0]
	at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapper.map(ServiceModelToOpenApiMapper.java:216) ~[springfox-oas-3.0.0.jar:3.0.0]
	at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapperImpl.mapOperation(ServiceModelToOpenApiMapperImpl.java:113) ~[springfox-oas-3.0.0.jar:3.0.0]
	at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapper.mapOperations(ServiceModelToOpenApiMapper.java:283) ~[springfox-oas-3.0.0.jar:3.0.0]
	at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapper.lambda$mapPaths$4(ServiceModelToOpenApiMapper.java:264) ~[springfox-oas-3.0.0.jar:3.0.0]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[?:?]
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655) ~[?:?]
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658) ~[?:?]
	at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:274) ~[?:?]
	at java.util.TreeMap$ValueSpliterator.forEachRemaining(TreeMap.java:2890) ~[?:?]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[?:?]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[?:?]
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
	at java.util.stream.ReferencePipeline.forEachOrdered(ReferencePipeline.java:502) ~[?:?]
	at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapper.mapPaths(ServiceModelToOpenApiMapper.java:260) ~[springfox-oas-3.0.0.jar:3.0.0]
	at springfox.documentation.oas.mappers.ServiceModelToOpenApiMapperImpl.mapDocumentation(ServiceModelToOpenApiMapperImpl.java:83) ~[springfox-oas-3.0.0.jar:3.0.0]
	at springfox.documentation.oas.web.OpenApiControllerWebMvc.getDocumentation(OpenApiControllerWebMvc.java:88) ~[springfox-oas-3.0.0.jar:3.0.0]

Variables at that time: source=ModelSpecification[scalar=null, compound=null, collection=null, map=null, reference=ReferenceModelSpecification{modelKey=ModelKey{qualifiedModelName=ModelName{namespace=‘’, name=‘null’}, viewDiscriminator=null, validationGroupDiscriminators=[], isResponse=true}}, facets=null, name=‘null’] facets=Optional.empty

The v2/api-docs?group=api endpoint is working and it worked before upgrading to version 3.0.0. Following operation/rest controller seems to trigger this (kotlin):

import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType.APPLICATION_JSON_VALUE
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod.POST
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController

@RestController
@Api(tags = ["some tag"])
@Deprecated("no longer supported. ")
class RestController(private val service: SomeService) {
    @RequestMapping(path = [URL_CALL], method = [POST], consumes = [APPLICATION_JSON_VALUE])
    @ApiOperation(value = "Logs and stores a message")
    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    fun call(
            @RequestBody
            @ApiParam(name = "call", value = "data to be stored")
            call: MutableMap<String, Any?>) {
        service.log(call)
    }

    companion object {
        const val URL_CALL = "api" + "/calls"
    }
}```

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

4reactions
kdebski85commented, Dec 23, 2020

I confirm that returning ResponseEntity instead of void is a working workaround.

It is best to return ResponseEntity<Void>. You can return it with ResponseEntity.noContent().build().

I did some debugging and SchemaMapper fails when it tries to map response code 200. But there should not be that code at all. Void methods use result code 204 to indicate success.

2reactions
illidan80commented, Nov 9, 2020

BTW, workaround is to return ResponseEntity<String> instead of void, like this:

@RestController
public class TestController {

    @ApiOperation("an endpoint")
    @PostMapping(value = "/endpoint/", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> endpoint () {
        // do stuff here
       return ResponseEntity.ok().build();
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Java HashMap get method null pointer exception
If there is no entity with required Character in map, then map.get(key) returns null and inside if statement it leads to NullPointerException throwing....
Read more >
Null Pointer exception on a Map get()
If zero rows would be returned, there's no entry in the map for the record, so you need to check for that first:...
Read more >
NullPointerException in mapping - Google Groups
Hi, I have a little problem with mappings I don't know how to solve. I am using relational mapping to map bidirectionally between...
Read more >
NULL POINTER EXCEPTION IN MODEL COMPILER ... - IBM
NullPointerException at com.ibm.xtools.modelcompiler.core.storage.impl. ... If project is missing from projects map file the following error message will be ...
Read more >
Null Pointer Exception In Java - GeeksforGeeks
NullPointerException is thrown when program attempts to use an object reference that has the null value. These can be: Invoking a method from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found