Skip to content

Commit bdf2f4c

Browse files
authored
Merge pull request #3767 from 1c-syntax/copilot/fix-nullpointerexception-node-null
Fix NullPointerException in VariableSymbolComputer when parsing malformed lValue
2 parents cc6edd3 + a0a1488 commit bdf2f4c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/context/computer/VariableSymbolComputer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public ParseTree visitParam(BSLParser.ParamContext ctx) {
165165
public ParseTree visitLValue(BSLParser.LValueContext ctx) {
166166
if (
167167
ctx.getChildCount() > 1
168+
|| ctx.IDENTIFIER() == null
168169
|| currentMethodVariables.containsKey(ctx.getText())
169170
|| moduleVariables.containsKey(ctx.getText())
170171
) {

src/test/java/com/github/_1c_syntax/bsl/languageserver/context/computer/VariableSymbolTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.stream.Collectors;
3737

3838
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.assertj.core.api.Assertions.assertThatCode;
3940

4041
@SpringBootTest
4142
class VariableSymbolTest {
@@ -148,4 +149,24 @@ void testVariableKind() {
148149

149150
}
150151

152+
@Test
153+
void testNoNPEOnMalformedLValue() {
154+
// Test for issue BSL-LANGUAGE-SERVER-G5
155+
// Malformed code with syntax errors should not cause NPE
156+
String code = """
157+
Процедура Тест()
158+
Переменная =;
159+
=;
160+
Док.Записать;
161+
КонецПроцедуры
162+
""";
163+
164+
// Symbol tree construction happens during getDocumentContext
165+
// and should not throw NullPointerException
166+
assertThatCode(() -> {
167+
var ctx = TestUtils.getDocumentContext(code);
168+
ctx.getSymbolTree().getVariables();
169+
}).doesNotThrowAnyException();
170+
}
171+
151172
}

0 commit comments

Comments
 (0)