grails / grails-core

The Grails Web Application Framework
http://grails.org
Apache License 2.0
2.79k stars 949 forks source link

@Transactional could cause method to throw NPE #10385

Closed snimavat closed 7 years ago

snimavat commented 7 years ago

Looks like TransactionalTransform breaks in some rare situations

If Service A extends Service B, and when both has Transactional annotation. if Service A gets compiled before Service B, and when a class has service A injected into it, calling the transactional method on A results in NPE because of null Transaction manager

The reason seems how the transactional AST is done. when AST gets applied to both super/sub classes, the transactionManager in subclass would hide transactionManager in super class. so transactionManager is always null in super class, and when a super class method is called, it results in NPE

Environment Information

Example Application

Look at the attached example application, and run tests, you would see the test fails because of NPE

bugwork.zip

snimavat commented 7 years ago

Looks like this affect 2.x only...