Skip to content

Commit 48dbf77

Browse files
committed
GH-1434: wrapped all remaining calls to getLiteralValue via ASTUtils to avoid threading issues
Fixes GH-1434
1 parent c4af955 commit 48dbf77

21 files changed

+50
-35
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/annotations/AnnotationAttributeCompletionProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.jdt.core.dom.SimpleName;
3030
import org.eclipse.jdt.core.dom.StringLiteral;
3131
import org.springframework.ide.vscode.boot.java.handlers.CompletionProvider;
32+
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
3233
import org.springframework.ide.vscode.commons.java.IJavaProject;
3334
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
3435
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
@@ -235,8 +236,7 @@ protected Set<String> alreadyMentionedValues(ASTNode node) {
235236
List<?> expressions = arrayNode.expressions();
236237
for (Object expression : expressions) {
237238
if (expression instanceof StringLiteral) {
238-
StringLiteral stringExr = (StringLiteral) expression;
239-
String value = stringExr.getLiteralValue();
239+
String value = ASTUtils.getLiteralValue((StringLiteral) expression);
240240
result.add(value);
241241
}
242242
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/DependsOnDefinitionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public List<LocationLink> getDefinitions(CancelChecker cancelToken, IJavaProject
5252
Annotation a = (Annotation) parent;
5353
IAnnotationBinding binding = a.resolveAnnotationBinding();
5454
if (binding != null && binding.getAnnotationType() != null && Annotations.DEPENDS_ON.equals(binding.getAnnotationType().getQualifiedName())) {
55-
String beanName = valueNode.getLiteralValue();
55+
String beanName = ASTUtils.getLiteralValue(valueNode);
5656

5757
if (beanName != null && beanName.length() > 0) {
5858
return findBeansWithName(project, beanName);

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/NamedDefinitionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public List<LocationLink> getDefinitions(CancelChecker cancelToken, IJavaProject
5454
Annotation a = (Annotation) parent;
5555
IAnnotationBinding binding = a.resolveAnnotationBinding();
5656
if (binding != null && binding.getAnnotationType() != null && Annotations.NAMED_ANNOTATIONS.contains(binding.getAnnotationType().getQualifiedName())) {
57-
String beanName = valueNode.getLiteralValue();
57+
String beanName = ASTUtils.getLiteralValue(valueNode);
5858

5959
if (beanName != null && beanName.length() > 0) {
6060
return findBeansWithName(project, beanName);

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/NamedReferencesProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
2626
import org.springframework.ide.vscode.boot.java.Annotations;
2727
import org.springframework.ide.vscode.boot.java.handlers.ReferenceProvider;
28+
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
2829
import org.springframework.ide.vscode.commons.java.IJavaProject;
2930
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
3031

@@ -50,14 +51,14 @@ public List<? extends Location> provideReferences(CancelChecker cancelToken, IJa
5051
// case: @Value("prefix<*>")
5152
if (node instanceof StringLiteral && node.getParent() instanceof Annotation) {
5253
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
53-
return provideReferences(project, ((StringLiteral) node).getLiteralValue());
54+
return provideReferences(project, ASTUtils.getLiteralValue((StringLiteral) node));
5455
}
5556
}
5657
// case: @Value(value="prefix<*>")
5758
else if (node instanceof StringLiteral && node.getParent() instanceof MemberValuePair
5859
&& "value".equals(((MemberValuePair)node.getParent()).getName().toString())) {
5960
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
60-
return provideReferences(project, ((StringLiteral) node).getLiteralValue());
61+
return provideReferences(project, ASTUtils.getLiteralValue((StringLiteral) node));
6162
}
6263
}
6364
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/ProfileReferencesProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
2626
import org.springframework.ide.vscode.boot.java.Annotations;
2727
import org.springframework.ide.vscode.boot.java.handlers.ReferenceProvider;
28+
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
2829
import org.springframework.ide.vscode.commons.java.IJavaProject;
2930
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
3031

@@ -48,20 +49,20 @@ public List<? extends Location> provideReferences(CancelChecker cancelToken, IJa
4849
// case: @Value("prefix<*>")
4950
if (node instanceof StringLiteral && node.getParent() instanceof Annotation) {
5051
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
51-
return provideReferences(project, ((StringLiteral) node).getLiteralValue());
52+
return provideReferences(project, ASTUtils.getLiteralValue((StringLiteral) node));
5253
}
5354
}
5455
// case: @Value(value="prefix<*>")
5556
else if (node instanceof StringLiteral && node.getParent() instanceof MemberValuePair
5657
&& "value".equals(((MemberValuePair)node.getParent()).getName().toString())) {
5758
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
58-
return provideReferences(project, ((StringLiteral) node).getLiteralValue());
59+
return provideReferences(project, ASTUtils.getLiteralValue((StringLiteral) node));
5960
}
6061
}
6162
// case: @Qualifier({"prefix<*>"})
6263
else if (node instanceof StringLiteral && node.getParent() instanceof ArrayInitializer) {
6364
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
64-
return provideReferences(project, ((StringLiteral) node).getLiteralValue());
65+
return provideReferences(project, ASTUtils.getLiteralValue((StringLiteral) node));
6566
}
6667
}
6768
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/QualifierDefinitionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public List<LocationLink> getDefinitions(CancelChecker cancelToken, IJavaProject
5252
Annotation a = (Annotation) parent;
5353
IAnnotationBinding binding = a.resolveAnnotationBinding();
5454
if (binding != null && binding.getAnnotationType() != null && Annotations.QUALIFIER.equals(binding.getAnnotationType().getQualifiedName())) {
55-
String beanName = valueNode.getLiteralValue();
55+
String beanName = ASTUtils.getLiteralValue(valueNode);
5656

5757
if (beanName != null && beanName.length() > 0) {
5858
return findBeansWithName(project, beanName);

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/QualifierReferencesProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
2525
import org.springframework.ide.vscode.boot.java.Annotations;
2626
import org.springframework.ide.vscode.boot.java.handlers.ReferenceProvider;
27+
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
2728
import org.springframework.ide.vscode.commons.java.IJavaProject;
2829
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
2930

@@ -47,14 +48,14 @@ public List<? extends Location> provideReferences(CancelChecker cancelToken, IJa
4748
// case: @Value("prefix<*>")
4849
if (node instanceof StringLiteral && node.getParent() instanceof Annotation) {
4950
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
50-
return provideReferences(project, ((StringLiteral) node).getLiteralValue());
51+
return provideReferences(project, ASTUtils.getLiteralValue((StringLiteral) node));
5152
}
5253
}
5354
// case: @Value(value="prefix<*>")
5455
else if (node instanceof StringLiteral && node.getParent() instanceof MemberValuePair
5556
&& "value".equals(((MemberValuePair)node.getParent()).getName().toString())) {
5657
if (node.toString().startsWith("\"") && node.toString().endsWith("\"")) {
57-
return provideReferences(project, ((StringLiteral) node).getLiteralValue());
58+
return provideReferences(project, ASTUtils.getLiteralValue((StringLiteral) node));
5859
}
5960
}
6061
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/ResourceDefinitionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public List<LocationLink> getDefinitions(CancelChecker cancelToken, IJavaProject
5454
if (binding != null && binding.getAnnotationType() != null
5555
&& (Annotations.RESOURCE_JAVAX.equals(binding.getAnnotationType().getQualifiedName())
5656
|| Annotations.RESOURCE_JAKARTA.equals(binding.getAnnotationType().getQualifiedName()))) {
57-
String beanName = valueNode.getLiteralValue();
57+
String beanName = ASTUtils.getLiteralValue(valueNode);
5858

5959
if (beanName != null && beanName.length() > 0) {
6060
return findBeansWithName(project, beanName);

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/conditionals/ConditionalOnBeanDefinitionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public List<LocationLink> getDefinitions(CancelChecker cancelToken, IJavaProject
7272
}
7373

7474
private List<LocationLink> getDefinitions(IJavaProject project, StringLiteral valueNode) {
75-
String value = valueNode.getLiteralValue();
75+
String value = ASTUtils.getLiteralValue(valueNode);
7676

7777
if (value != null && value.length() > 0) {
7878
return getDefinitionsForValue(project, valueNode, value);

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/conditionals/ConditionalOnPropertyCompletionProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private String getPrefixAttributeValue(ASTNode node) {
139139
if (valuePairName != null && "prefix".equals(valuePairName)
140140
&& valuePair.getValue() != null && valuePair.getValue() instanceof StringLiteral) {
141141
StringLiteral prefixLiteral = (StringLiteral) valuePair.getValue();
142-
String valuePairValue = prefixLiteral.getLiteralValue();
142+
String valuePairValue = ASTUtils.getLiteralValue(prefixLiteral);
143143
return valuePairValue;
144144
}
145145
}

0 commit comments

Comments
 (0)