Skip to content

Add additional guard for web application detection in AOT #14147

Closed

Description

@dsyer

This code in SpringApplication blows up at runtime in a native image when WebApplicationContext is not on the classpath:

	private boolean isWebApplicationContext(Class<?> applicationContextClass) {
		try {
			return WebApplicationContext.class.isAssignableFrom(applicationContextClass);
		}
		catch (NoClassDefFoundError ex) {
			return false;
		}
	}

Probably we could add an additional check that WebApplicationContext is present before we check for isAssignableFrom() it?

Adding this check worked for me:

	    if (!ClassUtils.isPresent("org.springframework.web.context.WebApplicationContext", null)) {
	        return false;
	    }

but it didn't work to simply catch Throwable.

Activity

  1. added
    status: waiting-for-triage
    on Aug 20, 2018
  2. snicoll commented on Aug 20, 2018

    @snicoll
    Member

    That's a pattern we use in other places so if that becomes problematic, I'd prefer to understand where this is coming from.

  3. dsyer commented on Aug 20, 2018

    @dsyer
    MemberAuthor

    I haven't seen that pattern anywhere else in Spring or Spring Boot, which isn't to say that it's something we necessarily have to fix here. I opened oracle/graal#622, so we can see what they say over there before we do anything, I guess.

  4. snicoll commented on Aug 20, 2018

    @snicoll
    Member

    There is OnBeanCondition that does that or am I missing something?

  5. added
    status: blocked
    on Aug 20, 2018
  6. dsyer commented on Aug 20, 2018

    @dsyer
    MemberAuthor

    OnBeanCondition does not call isAssignableFrom(). Am I missing something?

  7. snicoll commented on Aug 20, 2018

    @snicoll
    Member

    No but I surely was. Sorry.

  8. added
    for: team-attention
    on Aug 27, 2018
  9. self-assigned this
    on Aug 29, 2018
  10. philwebb commented on Aug 29, 2018

    @philwebb
    Member

    See #14157 (comment). Closing for now and awaiting the result of oracle/graal#622

  11. added
    for: external-project
    and removed
    for: team-attention
    status: blocked
    status: waiting-for-triage
    on Aug 29, 2018
  12. added
    theme: aot
    on Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

for: external-projecttheme: aot

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions