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

deepCopy does not create an instance of the specific class #127

Open
hugoqnc opened this issue Sep 3, 2024 · 0 comments · May be fixed by #143
Open

deepCopy does not create an instance of the specific class #127

hugoqnc opened this issue Sep 3, 2024 · 0 comments · May be fixed by #143
Assignees
Labels
bug Something isn't working

Comments

@hugoqnc
Copy link
Contributor

hugoqnc commented Sep 3, 2024

Algorithm contains this deepCopy method:

    @Nonnull
    @Override
    public INode deepCopy() {
        Algorithm copy = new Algorithm(this);
        for (INode child : this.children.values()) {
            copy.children.put(child.getKind(), child.deepCopy());
        }
        return copy;
    }

All the algorithms (AES, ...) are extending Algorithm, so they get this deepCopy method. However, calling it on an AES object does not create an AES instance but an Algorithm instance (creating later problems when relying on instanceof, in the enricher for example).

To solve this, the only solution is probably to add each subclass of Algorithm a "copy" constructor (like AES(AES aes), calling the super "copy" constructor of Algorithm given below) and to overwrite the deepCopy() method, in which we instantiate a new AES using this constructor.

    private Algorithm(@Nonnull Algorithm algorithm) {
        this.children = new HashMap<>();
        this.kind = algorithm.kind;
        this.detectionLocation = algorithm.detectionLocation;
        this.name = algorithm.name;
    }
@hugoqnc hugoqnc added the bug Something isn't working label Sep 3, 2024
@n1ckl0sk0rtge n1ckl0sk0rtge linked a pull request Sep 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants