Skip to content

Invalid cast for overloaded method#2698

Merged
skylot merged 1 commit intoskylot:masterfrom
nitram84:overloaded_invoke_no_cast
Nov 11, 2025
Merged

Invalid cast for overloaded method#2698
skylot merged 1 commit intoskylot:masterfrom
nitram84:overloaded_invoke_no_cast

Conversation

@nitram84
Copy link
Copy Markdown
Contributor

The latest git version of jadx decompiles this class (compiled with openjdk8)

public class AbstractItem {

	public void doSomething(Container c, Item i) {
		c.add(i);
	}

	public static class Container {

		public <T extends AbstractItem> int add(T t) {
			return 0;
		}

		public void add(AbstractItem... item) {
		}
	}

	public static class Item extends AbstractItem {
	}
}

to

public class AbstractItem {

	public void doSomething(Container c, Item i) {
		c.add((Container)i); // <-- invalid cast
	}

	public static class Container {

		public <T extends AbstractItem> int add(T t) {
			return 0;
		}

		public void add(AbstractItem... item) {
		}
	}

	public static class Item extends AbstractItem {
	}
}

It seems the arg offsets were not respected in TypeUtils.getTypeVarMappingForInvoke(). After adding the arg offset the cast was gone.

Copy link
Copy Markdown
Owner

@skylot skylot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super! Thank you 👍

@skylot skylot merged commit 7ea478e into skylot:master Nov 11, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants