eclipse / lsp4jakarta

Language Server for Jakarta EE
Eclipse Public License 2.0
33 stars 50 forks source link

[VS Code] Quick-fix fails due to getData() is null #416

Open kathrynkodama opened 1 year ago

kathrynkodama commented 1 year ago

To reproduce Using jakarta-sample project in VS Code (Mac OS), trying to trigger quick-fixes on bean validation constraint diagnostics:

[Error - 12:57:13 PM] Request textDocument/codeAction failed.
  Message: Request jakarta/java/codeaction failed with message: java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "org.eclipse.lsp4j.Diagnostic.getData()" is null
  Code: -32603 
image
kathrynkodama commented 1 year ago

Encountered the same bug on Dependency Injection diagnostics, this quick-fix does not appear: https://github.com/eclipse/lsp4jakarta/blob/main/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.core/src/main/java/org/eclipse/lsp4jakarta/jdt/core/di/ConflictInjectMultipleConstructorQuickFix.java

for this class: https://github.com/eclipse/lsp4jakarta/blob/main/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.test/projects/jakarta-sample/src/main/java/io/openliberty/sample/jakarta/di/GreetingServlet.java

See the expected quick-fixes: https://github.com/eclipse/lsp4jakarta/blob/main/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.test/src/main/java/org/eclipse/lsp4jakarta/jdt/di/DependencyInjectionTest.java

[Error - 1:30:22 PM] Request textDocument/codeAction failed.
  Message: Request jakarta/java/codeaction failed with message: java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "org.eclipse.lsp4j.Diagnostic.getData()" is null
  Code: -32603 
kathrynkodama commented 1 year ago

Same error reported Jsonb Diagnostics, see this class for the expected quick fixes: https://github.com/eclipse/lsp4jakarta/blob/main/jakarta.jdt/org.eclipse.lsp4jakarta.jdt.test/src/main/java/org/eclipse/lsp4jakarta/jdt/jsonb/JsonbDiagnosticsCollectorTest.java

turkeylurkey commented 1 year ago

Diagnostic received from LS:

[Trace - 2:31:17 PM] Received response 'workspace/executeCommand - (28)' in 604ms.
Result: [
    {
        "uri": "file:///Users/tl/jakarta-sample/src/main/java/io/openliberty/sample/jakarta/beanvalidation/FieldConstraintValidation1.java",
        "diagnostics": [
            {
                "range": {
                    "start": {
                        "line": 7,
                        "character": 16
                    },
                    "end": {
                        "line": 7,
                        "character": 23
                    }
                },
                "severity": 1,
                "code": "FixTypeOfElement",
                "source": "jakarta-bean-validation",
                "message": "The @AssertTrue annotation can only be used on boolean and Boolean type fields.",
                "data": "AssertTrue"
            }
        ]
    }
]

diagnostic sent along with quick fix request, one field missing:

[Trace - 2:58:14 PM] Sending request 'textDocument/codeAction - (62)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/tl/jakarta-sample/src/main/java/io/openliberty/sample/jakarta/beanvalidation/FieldConstraintValidation1.java"
    },
    "range": {
        "start": {
            "line": 7,
            "character": 16
        },
        "end": {
            "line": 7,
            "character": 23
        }
    },
    "context": {
        "diagnostics": [
            {
                "range": {
                    "start": {
                        "line": 7,
                        "character": 16
                    },
                    "end": {
                        "line": 7,
                        "character": 23
                    }
                },
                "message": "The @AssertTrue annotation can only be used on boolean and Boolean type fields.",
                "code": "FixTypeOfElement",
                "severity": 1,
                "source": "jakarta-bean-validation"
            }
        ],
        "only": [
            "quickfix"
        ],
        "triggerKind": 1
    }
}
turkeylurkey commented 1 year ago

Opened issue: https://github.com/microsoft/vscode/issues/181166

TrevCraw commented 1 year ago

@dshimo recorded hitting this issue in #460

turkeylurkey commented 1 year ago

Affects diagnostics that use: -ScopeDeclarationQuickFix -BeanValidationQuickFix -JsonbTransientAnnotationQuickFix -ManagedBeanConstructorQuickFix -ManagedBeanQuickFix -PersistenceAnnotationQuickFix -CompleteFilterAnnotationQuickFix -CompleteServletAnnotationQuickFix