Skip to content

Overloading not accounting for arguments type for state transitions #134

Description

@CatarinaGamboa

I think there's a bug in selecting the correct method to check when there are two methods with the same number of arguments but different types.

This was the example where I encountered the issue.

This class has two constructors with only 1 argument, but they go to different states. With the first, it's okay to call initCause, with the second, it is not.

@StateSet({"start", "hasMessage", "hasCause"})
@ExternalRefinementsFor("java.lang.Throwable")
public interface ThrowableRefinements {

    // ##### Constructors #######
    @StateRefinement(to="hasMessage(this)")
    public void Throwable(String message);

    @StateRefinement(to="hasCause(this)")
    public void Throwable(Throwable cause);

    @StateRefinement(from="!hasCause(this)", to="hasCause(this)")
    public Throwable initCause(Throwable cause);
}

Tests where we can see the issue:

public class Test{
    void test3(){
        Throwable t = new Throwable("Example");
        t.initCause(null);
        t.getCause();
    }

    void test4(){
        Throwable originT = new Throwable();
        Throwable t = new Throwable(originT); // should be an error but its not
        t.initCause(null);
        t.getCause();
    }

}

Now, what leads me to think this is an issue in selecting the methods is that we get errors in both test cases if:

  • we remove the constructor with string
  • change the order of the two constructors

Activity

  1. changed the title [-]Overloading not accounting for type for state transitions[/-] [+]Overloading not accounting for arguments type for state transitions[/+] on Dec 12, 2025
  2. rcosta358 commented on Dec 12, 2025

    @rcosta358
    Collaborator

    Yep, I mentioned this problem in #62:

    This can be improved in the future by distinguishing methods not only by parameter count but also by parameter types.

    Thanks for opening the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions