Skip to content

Commit 1518f05

Browse files
committed
GH-1730: avoid exception due to completion being invoked beyond string literal boundaries
1 parent b9d89b9 commit 1518f05

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -160,6 +160,10 @@ private void computeProposalsForSimpleName(IJavaProject project, ASTNode node, C
160160
}
161161

162162
private void computeProposalsForStringLiteral(IJavaProject project, StringLiteral node, Collection<ICompletionProposal> completions, int offset, TextDocument doc) throws BadLocationException {
163+
if (node.getStartPosition() + node.getLength() <= offset) {
164+
return;
165+
}
166+
163167
String prefix = identifyPropertyPrefix(doc.get(node.getStartPosition() + 1, offset - (node.getStartPosition() + 1)), offset - (node.getStartPosition() + 1));
164168

165169
int startOffset = offset - prefix.length();

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/value/test/ValueCompletionTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -184,6 +184,13 @@ void testEmptyBracketsCompletionWithParamName() throws Exception {
184184
"@Value(value=\"classpath:org/test/random-resource-org-test.txt\"<*>)");
185185
}
186186

187+
@Test
188+
void testCursorBehindStringLiteralEmptyCompletions() throws Exception {
189+
prepareCase("@Value(\"onField\")", "@Value(\"something\"<*>)");
190+
assertPropertyCompletions();
191+
assertClasspathCompletions();
192+
}
193+
187194
@Test
188195
void testEmptyBracketsCompletionWithWrongParamName() throws Exception {
189196
prepareCase("@Value(\"onField\")", "@Value(another=<*>)");

0 commit comments

Comments
 (0)