Function failing for "Oops! An unexpected error occurred: java.lang.NullPointerException"
Issue description: We have spring cloud function deployed to azure function app. The project was built with Gradle and released from DevOps. The function is failing for error "Oops! An unexpected error occurred: java.lang.NullPointerException". Another deployment might fix this issue without any code modification.
Info: We have the same project deployed to 2 function apps via the exact deployment pipeline and created a working and another non-working scenarios. I would like to share the function urls, but urls contain function keys so not sure if it is a good idea to show here. I can also share the sample project that could reproduce this issue. So if needed, please let me know.
Since this issue could be mitigated without changing the source code, we suspect that it is related to the Spring Cloud functions framework or how it was build by Gradle.
We also found that this issue might be related to the OS environment. For example, the working function app works on Linux but not on Windows. The non-working function app does not work on Linux but work on Windows.
The main code part that act as function is
class GraphQlAzureFunction extends FunctionInvoker[Message[String], SystemGraphQlResponse] {
/**
* Return HttpResponseMessage with body containing JsonString.
*/
@FunctionName(GraphQlFunction.FUNCTION_NAME)
def execute(
@HttpTrigger(
name = "graphQlRequest",
methods = Array(HttpMethod.POST),
authLevel = AuthorizationLevel.FUNCTION
)
httpRequest: HttpRequestMessage[String],
context: ExecutionContext
): HttpResponseMessage = {
val msg = MessageBuilder.withPayload(httpRequest.getBody).copyHeaders(httpRequest.getHeaders).build()
try {
val res = handleRequest(msg, context)
buildHttpResponse(httpRequest, res)
} catch {
case ex: Throwable =>
buildHttpResponse(httpRequest, SystemGraphQlResponse.ofException(ex))
}
}
Ask: Need Spring team to help understand this issue
Where is the stack-trace???
Hi @olegz , thank you for checking! The stack trace:
{
"errors": [
{
"message": "Oops! An unexpected error occurred: java.lang.NullPointerException",
"locations": [],
"extensions": {
"messageKey": "CommonUnexpectedError",
"args": [],
"message": "Oops! An unexpected error occurred: java.lang.NullPointerException",
"invalidFields": [],
"origin": {
"causedBy": {
"class": "java.lang.NullPointerException"
},
"topThrownBy": {
"class": "org.springframework.cloud.function.adapter.azure.FunctionInvoker",
"method": "handleRequest",
"file": "FunctionInvoker.java",
"line": 129
},
"bottomThrownBy": {
"class": "com.lpg.util_213.spring.cloud.function.graphql.azure.function.GraphQlAzureFunction",
"method": "execute",
"file": "GraphQlAzureFunction.scala",
"line": 31
}
},
"classification": "ExecutionAborted"
}
}
]
}
If anything else needed, please let me know.
I see that the issue is tagged as AWS. It is actually Azure.
Hi team, is there any thing else needed for next action? Please feel free to let me know.
@Yangsh-w based on your stack trace the error originates in com.lpg.util_213.spring.cloud.function.graphql.azure.function.GraphQlAzureFunction which is not a framework class, so not sure what to say. In other words the exception happens in your class.
If you can share a sample project that reproduces the issue that would help
Hi @olegz , Thank you so much for the information shared! Sorry for this late update, I was not able to log in in the past days due to an unforeseen outage.
Yes, we have a sample project that can reproduce this issue. But this project is not owned by me, I need some time to ask for permission to share it here. Thanks a lot!
Hi @olegz, Is there any way we could share the sample project privately? For example to you only?
No you can not. Instead, you can create a new sample project which contains only enough to reproduce the issue. So there should not be any sensitive information
Thank you @olegz , I will confirm with the project owner see if we could make a public version. I will keep our thread updated.
Hi @olegz , the owner of this project is not available to create and provide a public sample project at the moment. Do you mind we temporarily close this issue thread and we will provide a response once the project is available? Thanks!
Sure, closing it as requested, feel free to reopen when you ready