Skip to content

Commit

Permalink
fix(languages/java): avoid infinite stack overflow for FindSymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Mar 13, 2024
1 parent bd33cc1 commit 57ce740
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion languages/java/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ func (an *javaAnalyzer) FallbackSymbol() lib.Symbol {
}

func (an *javaAnalyzer) FindSymbol(name string) lib.Symbol {
return an.findSymbolWithRetries(name, 0)
}

func (an *javaAnalyzer) findSymbolWithRetries(name string, retry int) lib.Symbol {
if retry > 3 {
// do not retry more than 3 times or it will cause stack overflow
return lib.UnresolvedSymbol
}

sym, ok := builtinTypesStore.FindByName(name)
if ok {
return sym
Expand Down Expand Up @@ -86,7 +95,7 @@ func (an *javaAnalyzer) FindSymbol(name string) lib.Symbol {
}

// if parsed, find the symbol again
return an.FindSymbol(name)
return an.findSymbolWithRetries(name, retry+1)
}

func (an *javaAnalyzer) markAsUnresolved(name string) lib.Symbol {
Expand Down

0 comments on commit 57ce740

Please sign in to comment.