-
Notifications
You must be signed in to change notification settings - Fork 41.2k
NPE in BeanDefinitionLoader when loading non-Class sources and XML support is disabled #22696
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
NPE in BeanDefinitionLoader when loading non-Class sources and XML support is disabled #22696
Conversation
We talked a bit about this last week. We're increasingly uncomfortable with these Graal-specific changes that are hard to test. Our assumption had been that any problems would be detected by the Spring Graal Native project but it appears to have been missed there too. @sdeleuze I think we need to revisit our approach here. We either need to figure how how to test these changes in Boot (without relying on Graal) or we need a commitment on your side to test things. |
With a change to make package org.springframework.boot;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.boot.testsupport.classpath.ModifiedClassPathExtension;
import org.springframework.context.support.StaticApplicationContext;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@ExtendWith(ModifiedClassPathExtension.class)
class IgnoringXmlBeanDefinitionLoaderTests {
@BeforeAll
static void ignoreXml() {
System.setProperty("spring.xml.ignore", "true");
}
@AfterAll
static void enableXml() {
System.clearProperty("spring.xml.ignore");
}
@Test
void whenXmlSupportIsDisabledXmlSourcesAreRejected() {
assertThatExceptionOfType(BeanDefinitionStoreException.class)
.isThrownBy(() -> new BeanDefinitionLoader(new StaticApplicationContext(),
"classpath:org/springframework/boot/sample-beans.xml").load())
.withMessage("Cannot load XML bean definitions when XML support is disabled");
}
} |
Thanks very much, @dreis2211. |
That's a neat trick to use |
I wonder if we should rather introduce a new annotation |
I was in two minds about that, and I still am really. I don't have any objection to introducing a custom annotation. I guess we'd want to prevent |
Mind if I experiment with that if I find the time? |
Not at all. That'd be great! |
Hi,
I was playing with
spring.xml.ignore
and found an NPE when loading CharSequence sources.The following application snippet should reproduce the error
When running
java -Dspring.xml.ignore=true -jar app.jar
the following NPE occurs:This is due to the fact that
xmlReader
is null when XML support is disabled. As the reader is only used to get theEnvironment
, I think we can workaround this by just using thescanner
field. They should have the sameEnvironment
here.Unfortunately, it's a bit cumbersome to write a test for this. I would need to set the final
xmlReader
field to null via reflection, which is what I try to avoid usually. Nonetheless, let me know If I should add a test like described that mimics XML support being disabled.Cheers,
Christoph
P.S.: I tried setting
spring.xml.ignore
in myapplication.properties
first, which didn't work. I think we would need to useBinder
facilities to make this work. Maybe that's worth evaluating.