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

SerializableTypeWrapper does not consistently catch InvocationTargetException #30764

Closed
tohidemyname opened this issue Jun 28, 2023 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@tohidemyname
Copy link

The code is as follows:

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (Type.class == method.getReturnType() && ObjectUtils.isEmpty(args)) {
return forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, -1));
}
else if (Type[].class == method.getReturnType() && ObjectUtils.isEmpty(args)) {
Type[] result = new Type[((Type[]) method.invoke(this.provider.getType())).length];// also calls method.invoke()
for (int i = 0; i < result.length; i++) {
result[i] = forTypeProvider(new MethodInvokeTypeProvider(this.provider, method, i));
}
return result;
}

		try {
			return method.invoke(this.provider.getType(), args);
		}
		catch (InvocationTargetException ex) {
			throw ex.getTargetException();
		}
	}

The following code line also calls invoke, but it is not inside the try statement:

Type[] result = new Type[((Type[]) method.invoke(this.provider.getType())).length];

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 28, 2023
@jhoeller
Copy link
Contributor

Well spotted, this can potentially miss the exception adaptation indeed, even if exceptions are rarely seen there to begin with. In fact those calls should use ReflectionUtils.invokeMethod where we perform that adaptation automatically.

@jhoeller jhoeller changed the title SerializableTypeWrapper can ignore a invoke method SerializableTypeWrapper does not consistently catch InvocationTargetException Jun 28, 2023
@jhoeller jhoeller added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 28, 2023
@jhoeller jhoeller self-assigned this Jun 28, 2023
@jhoeller jhoeller added this to the 6.0.11 milestone Jun 28, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x labels Jun 28, 2023
jhoeller added a commit that referenced this issue Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants