Skip to content

Clarify intended advice execution behavior in Spring version 5.2.7+ #26202

@ranjit-g

Description

@ranjit-g

Affects: 5.2.7.RELEASE

StackOverflow question : https://stackoverflow.com/q/65032499/4214241

Sample Github project shared for the question : https://github.com/RitamChakraborty/bank_transaction_springaop/tree/r_g_answer

Issue descrption :

The following @AfterThrowing advice does not work as expected in Spring versions above : 5.2.6.RELEASE


@After("execution(public void dev.ritam.model.Bank.setTempPin(..))")
public void validatePin() {
    if (bank.getPinCode() != bank.getTempPin()) {
        throw new RuntimeException("Wrong Pin");
    } else {
        System.out.println("Correct Pin");
    }
}

@AfterThrowing(value = "execution(public void dev.ritam.model.Bank.setTempPin(..))", throwing = "e")
public void logException(Exception e) {
    System.out.println(e.getMessage());
}


For spring versions above : 5.2.6.RELEASE ( tested with releases 5.2.7.RELEASE,5.2.8.RELEASE,5.2.9.RELEASE,5.3.1)

@AfterThrowing advice does not execute on exception from @After advice. The same results if @After advice is replaced with @Before.

For spring versions equal to or below : 5.2.6.RELEASE ( tested with releases 5.2.6.RELEASE,5.2.5.RELEASE,5.2.4.RELEASE, 5.2.3.RELEASE) , the advice happens from @AfterThrowing on exception from @After

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions