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

TypeDiscoverer.getParameterTypes does not capture enclosing type parameter of non static inner class #2313

Closed
christophstrobl opened this issue Feb 25, 2021 · 0 comments
Assignees
Labels
in: core Issues in core support type: bug A general bug

Comments

@christophstrobl
Copy link
Member

static class SomeGeneric<T> {

	private final T value;

	protected SomeGeneric(T value) {
		this.value = value;
	}
}

class NonStaticInnerWithGenericFieldInSuper<T> extends SomeGeneric<T> {

	public NonStaticInnerWithGenericFieldInSuper(T value) {
		super(value);
	}
}

@Test
void capturesEnclosingTypeParameterOfNonStaticInnerClass() {

	assertThat(PreferredConstructorDiscoverer.discover(NonStaticInnerWithGenericFieldInSuper.class)).satisfies(ctor -> {

		assertThat(ctor.getParameters()).hasSize(2);
		assertThat(ctor.getParameters().get(0).getName()).isEqualTo("this$0");
		assertThat(ctor.getParameters().get(1).getName()).isEqualTo("value");
	});
}

It seems Constructor.getGenericParameterTypes() does only return the enclosing types one. Using Constructor.getParameters() can help read the Type via Parameter.getParameterizedType of each Parameter.

@christophstrobl christophstrobl self-assigned this Feb 25, 2021
@christophstrobl christophstrobl added in: core Issues in core support type: bug A general bug labels Feb 25, 2021
@mp911de mp911de added this to the 2.3.8 (Neumann SR8) milestone Mar 1, 2021
mp911de pushed a commit that referenced this issue Mar 1, 2021
This commit fixes an issue where we fail to detect all type arguments from a given constructor. calling getGenericParameterTypes in some cases does not include all Types, we now explicitly iterate over the parameters and extract the parameterized type that is used for creating the TypeInformation.

Closes: #2313
Original pull request: #2314.
mp911de added a commit that referenced this issue Mar 1, 2021
Reformat code.

Original pull request: #2314.
Closes: #2313
@mp911de mp911de closed this as completed in 8917115 Mar 1, 2021
mp911de added a commit that referenced this issue Mar 1, 2021
Reformat code.

Original pull request: #2314.
Closes: #2313
mp911de pushed a commit that referenced this issue Mar 1, 2021
This commit fixes an issue where we fail to detect all type arguments from a given constructor. calling getGenericParameterTypes in some cases does not include all Types, we now explicitly iterate over the parameters and extract the parameterized type that is used for creating the TypeInformation.

Closes: #2313
Original pull request: #2314.
mp911de added a commit that referenced this issue Mar 1, 2021
Reformat code.

Original pull request: #2314.
Closes: #2313
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: bug A general bug
Projects
None yet
2 participants