Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different nodes have same hashcode #4390

Open
Laughh opened this issue Apr 26, 2024 · 3 comments
Open

Different nodes have same hashcode #4390

Laughh opened this issue Apr 26, 2024 · 3 comments
Labels
Question (AST) Questions about nodes and relationships within the AST (not about how to use JavaParser)

Comments

@Laughh
Copy link

Laughh commented Apr 26, 2024

Hello! I'm using JP, and in the following code, I found that variables have the same hashCode in different scopes

public void hash(){
    {
        // 1
        Object cnt = new Object();
        cnt.equals(null);
    }
    {
        // 2
        Object cnt = new Object();
        cnt.equals(null);
    }

}

Here is the output. The ranges are different, but the hash code is Identical value. And is there any way to distinguish the two VariableDeclarators by hash code?

cnt = new Object()
Optional[(line 56,col 20)-(line 56,col 37)]
-628174007
--------------------
cnt = new Object()
Optional[(line 61,col 20)-(line 61,col 37)]
-628174007
--------------------
@jlerbsc
Copy link
Collaborator

jlerbsc commented Apr 27, 2024

Hi, The hashcode calculation for a variable declaration is based on the name, type, comments and initialisation expression attributes.

@jlerbsc jlerbsc added the Question (AST) Questions about nodes and relationships within the AST (not about how to use JavaParser) label Apr 27, 2024
@Laughh
Copy link
Author

Laughh commented Apr 27, 2024

But why the range are not considered?

@jlerbsc
Copy link
Collaborator

jlerbsc commented Apr 27, 2024

I don't know exactly. It's a functional equality which is obtained by an in-depth check of all the attributes which describe a node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question (AST) Questions about nodes and relationships within the AST (not about how to use JavaParser)
Projects
None yet
Development

No branches or pull requests

2 participants