Skip to content
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

Fixes #416 - Quick-fix fails due to getData() is null #536

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

aparnamichael
Copy link
Contributor

Fixes #416

Quick-fix fails due to getData() is null.
The root cause of the issue is lsp4Jakarta expects a Map object from VS Code, but we are sending a string or array of strings from VS code. Resolved the null pointer exception by adding code to handle both the 'data' format.

eg:
data = “AssertTrue”
data =[“ApplicationScoped", "RequestScoped”]

import java.util.stream.Collectors;

import org.eclipse.lsp4j.CodeActionContext;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.eclipse.lsp4jakarta.jdt.internal.beanvalidation.RemoveDynamicConstraintAnnotationQuickFix;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this unused import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public static Object getValueFromDataParameter(Map<String, Object> data, String key) {

Object child = data.get(key);
if (child != null && child instanceof String) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need this null check because child will not be an instance of String if it is null. Please remove the null check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Object child = data.get(key);
if (child != null && child instanceof String) {
// if the value in the 'data' is a string, we string the object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code does not line up because there is a tab character on the line. Please remove the tab and replace with 4 spaces.
The same goes for the following line, the two comment lines in the next if block and one comment line in the subsequent else block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return jsonArray;
} else {
//Returns the object if it exists and is an object, and null otherwise
return getObject(data, key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify why we need this line? It checks if the data is a Map?

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

Successfully merging this pull request may close these issues.

[VS Code] Quick-fix fails due to getData() is null
2 participants