spring-cloud-function icon indicating copy to clipboard operation
spring-cloud-function copied to clipboard

Function failing for "Oops! An unexpected error occurred: java.lang.NullPointerException"

Open Yangsh-w opened this issue 3 years ago • 7 comments

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

Yangsh-w avatar Aug 03 '22 07:08 Yangsh-w

Where is the stack-trace???

olegz avatar Aug 03 '22 13:08 olegz

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.

Yangsh-w avatar Aug 05 '22 10:08 Yangsh-w

I see that the issue is tagged as AWS. It is actually Azure.

khkh-ms avatar Aug 05 '22 18:08 khkh-ms

Hi team, is there any thing else needed for next action? Please feel free to let me know.

Yangsh-w avatar Aug 09 '22 01:08 Yangsh-w

@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

olegz avatar Aug 09 '22 15:08 olegz

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!

Yangsh-w avatar Aug 16 '22 04:08 Yangsh-w

Hi @olegz, Is there any way we could share the sample project privately? For example to you only?

Yangsh-w avatar Aug 16 '22 09:08 Yangsh-w

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

olegz avatar Aug 16 '22 14:08 olegz

Thank you @olegz , I will confirm with the project owner see if we could make a public version. I will keep our thread updated.

Yangsh-w avatar Aug 17 '22 02:08 Yangsh-w

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!

Yangsh-w avatar Aug 19 '22 04:08 Yangsh-w

Sure, closing it as requested, feel free to reopen when you ready

olegz avatar Aug 31 '22 15:08 olegz