Skip to content

Commit 779d969

Browse files
Copilotnixel2007
andcommitted
Fix NullPointerException in VariableSymbolComputer.visitLValue by adding null check
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
1 parent ced8518 commit 779d969

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,23 @@ void testVariableKind() {
148148

149149
}
150150

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

0 commit comments

Comments
 (0)