intellij-dlanguage / intellij-dlanguage

Intellij Plugin for the D Programming Language
MIT License
328 stars 51 forks source link

StackOverflowError in DUtil getPrevSiblingOfType #577

Open SingingBush opened 4 years ago

SingingBush commented 4 years ago

reported from IDEA 2020.1.2 with plugin version 1.24.1

last action was EditorBackSpace

java.lang.StackOverflowError    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:86)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:92)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:92)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:92)
    at io.github.intellij.dlanguage.utils.DUtil...
SingingBush commented 4 years ago

This is a problem with both the formatting code in io.github.intellij.dlanguage.features.formatter.DFormattingModelBuilder and the recursion taking place in DUtil::getPrevSiblingOfType

For now I've made a slight tweak but further investigation is needed.

SingingBush commented 3 years ago

The formatting code is another area that needs improving and testing. It's probably worth making proper use of

    override fun getRangeAffectingIndent(file: PsiFile, offset: Int, elementAtOffset: ASTNode): TextRange? {
        return null
    }
SingingBush commented 3 years ago

reported from AppCode 2021.2 (plugin 1.26.1):

java.lang.StackOverflowError: null
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:89)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
SingingBush commented 6 months ago

this is still an issue in 1.33.1:

java.lang.StackOverflowError: null
    at java.util.HashMap.hash(HashMap.java:338)
    at java.util.HashMap.getNode(HashMap.java:568)
    at java.util.HashMap.containsKey(HashMap.java:594)
    at java.util.HashSet.contains(HashSet.java:205)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:92)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)
    at io.github.intellij.dlanguage.utils.DUtil.getPrevSiblingOfType(DUtil.java:95)

there needs to be a limit on how many times this method is called using recursion: https://github.com/intellij-dlanguage/intellij-dlanguage/blob/d2cbe3acbc3cdaecceb6ae9404368e63c6ee3047/src/main/java/io/github/intellij/dlanguage/utils/DUtil.java#L72-L81

rikkimax commented 6 months ago

Looks like a rewrite is needed to get rid of the recursion:

while(child != null) {
    if (child.getElementType() == type)
        return child.getTreePrev();
    child = child.getTreePrev();
}

return null;