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.

Comment From: snicoll

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

Comment From: dsyer

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 https://github.com/oracle/graal/issues/622, so we can see what they say over there before we do anything, I guess.

Comment From: snicoll

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

Comment From: dsyer

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

Comment From: snicoll

No but I surely was. Sorry.

Comment From: philwebb

See https://github.com/spring-projects/spring-boot/issues/14157#issuecomment-417030452. Closing for now and awaiting the result of https://github.com/oracle/graal/issues/622