Skip to content

Ensure indexer gracefully handle missing meta annotations #22385

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

Closed
wants to merge 1 commit into from

Conversation

vpavic
Copy link
Contributor

@vpavic vpavic commented Feb 7, 2019

If spring-context-indexer is used in an application that uses @javax.transaction.Transactional, compilation will fail due to javax.interceptor.InterceptorBinding not being available.

This can be easily reproduced with a project as simple as:

plugins {
    id 'java'
    id 'io.spring.dependency-management' version '1.0.6.RELEASE'
    id 'org.springframework.boot' version '2.1.2.RELEASE'
}

sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'com.h2database:h2'
    annotationProcessor 'org.springframework:spring-context-indexer'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
@SpringBootApplication
@javax.transaction.Transactional
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
$ ./gradlew compileJava 

> Task :compileJava FAILED
error: cannot access InterceptorBinding
  class file for javax.interceptor.InterceptorBinding not found
  Consult the following stack trace for details.
  com.sun.tools.javac.code.Symbol$CompletionFailure: class file for javax.interceptor.InterceptorBinding not found
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed

This PR addresses the problem by adding a classpath presence check for annotation before proceeding to collect its stereotypes.

Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

I've actually noticed that issue working on a prototype for another feature on master. I don't like the idea of using reflection and perhaps we could catch an exception when collection meta annotations on an annotation that is not present? If we can narrow the catch to that specific use case, I think that is better than using Class.forName.

Thoughts?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Feb 8, 2019
@vpavic
Copy link
Contributor Author

vpavic commented Feb 8, 2019

If we can narrow the catch to that specific use case, I think that is better than using Class.forName.

Thoughts?

Sounds good to me - I'll try to update the PR accordingly at some point today.

@vpavic vpavic force-pushed the indexer-classpath branch from 3a67d82 to 42b9b69 Compare February 8, 2019 16:42
@vpavic
Copy link
Contributor Author

vpavic commented Feb 8, 2019

I've updated the PR so that we now catch an exception when collecting meta annotations.

@snicoll snicoll added type: bug A general bug and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 13, 2019
@snicoll snicoll added this to the 5.0.13 milestone Feb 13, 2019
@snicoll snicoll changed the title Ensure indexer verifies annotation classpath presence Ensure indexer gracefully handle missing meta annotations Feb 14, 2019
snicoll added a commit that referenced this pull request Feb 14, 2019
* pr/22385:
  Polish "Ensure indexer gracefully handle missing meta annotations"
  Ensure indexer gracefully handle missing meta annotations
@snicoll snicoll self-assigned this Feb 14, 2019
@snicoll snicoll closed this in 0cc77e8 Feb 14, 2019
@snicoll snicoll modified the milestones: 5.0.13, 5.1.6 Feb 14, 2019
@vpavic vpavic deleted the indexer-classpath branch February 14, 2019 09:23
@snicoll
Copy link
Member

snicoll commented Feb 14, 2019

Thanks @vpavic your fix was almost identical to the one I had in my spike for another feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants