java.lang.NullPointerException: null

Spring JIRA | Gabriele Del Prete | 1 year ago
  1. 0

    I'm updating my app from Spring 4.1.6 to 4.2.RC3. I have webjars-locator in myh classpath as we use webjars. With 4.2.RC3, the new WebJarsRecourceResolver kicks in and results in an NPE: {code:java} java.lang.NullPointerException: null at org.springframework.core.io.UrlResource.createRelative(UrlResource.java:223) ~[spring-core-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:121) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:94) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.PathResourceResolver.resolveResourceInternal(PathResourceResolver.java:78) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.AbstractResourceResolver.resolveResource(AbstractResourceResolver.java:46) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.DefaultResourceResolverChain.resolveResource(DefaultResourceResolverChain.java:57) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.WebJarsResourceResolver.resolveResourceInternal(WebJarsResourceResolver.java:66) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.AbstractResourceResolver.resolveResource(AbstractResourceResolver.java:46) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] {code} I checked the code and this (from WebJarsRecourceResolver) seems wrong: {code:java} @Override protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain) { String path = chain.resolveUrlPath(resourceUrlPath, locations); if (path == null) { String webJarResourcePath = findWebJarResourcePath(resourceUrlPath); return chain.resolveUrlPath(webJarResourcePath, locations); } return path; } {code} In fact, findWebJarResourcePath may very well return null, something that PathResourceResolver.getResource and UrlResource.createRelative do not like. This is my resource handling setup: {code:java} @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { boolean devMode = appConfig.isDevelopment(); final String location = devMode ? "file:///" + appConfig.getDevelopmentProjectRoot() + "myapp/src/" : "classpath:/static/"; int cachePeriod = devMode ? 0 : 31556926; // one year boolean useResourceCache = !devMode; registry .addResourceHandler("/static/**") .addResourceLocations(location) .setCachePeriod(cachePeriod) .resourceChain(useResourceCache).addResolver(new VersionResourceResolver().addContentVersionStrategy("/**")); // TODO: remove registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); if (devMode) { // in dev mode, we need access to the Bower components to load less.js registry .addResourceHandler("/bower_components/**") .addResourceLocations("file:///" + appConfig.getDevelopmentProjectRoot() + "frontend-project/bower_components/") .setCachePeriod(cachePeriod) .resourceChain(useResourceCache).addResolver(new VersionResourceResolver().addContentVersionStrategy("/**")); } } {code} The reources that trigger the NPE are all supposed to be loaded by my 'bower_components' folder (I load client code from the FS in development to speed up coding).

    Spring JIRA | 1 year ago | Gabriele Del Prete
    java.lang.NullPointerException: null
  2. 0

    I'm updating my app from Spring 4.1.6 to 4.2.RC3. I have webjars-locator in myh classpath as we use webjars. With 4.2.RC3, the new WebJarsRecourceResolver kicks in and results in an NPE: {code:java} java.lang.NullPointerException: null at org.springframework.core.io.UrlResource.createRelative(UrlResource.java:223) ~[spring-core-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:121) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:94) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.PathResourceResolver.resolveResourceInternal(PathResourceResolver.java:78) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.AbstractResourceResolver.resolveResource(AbstractResourceResolver.java:46) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.DefaultResourceResolverChain.resolveResource(DefaultResourceResolverChain.java:57) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.WebJarsResourceResolver.resolveResourceInternal(WebJarsResourceResolver.java:66) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] at org.springframework.web.servlet.resource.AbstractResourceResolver.resolveResource(AbstractResourceResolver.java:46) ~[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3] {code} I checked the code and this (from WebJarsRecourceResolver) seems wrong: {code:java} @Override protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain) { String path = chain.resolveUrlPath(resourceUrlPath, locations); if (path == null) { String webJarResourcePath = findWebJarResourcePath(resourceUrlPath); return chain.resolveUrlPath(webJarResourcePath, locations); } return path; } {code} In fact, findWebJarResourcePath may very well return null, something that PathResourceResolver.getResource and UrlResource.createRelative do not like. This is my resource handling setup: {code:java} @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { boolean devMode = appConfig.isDevelopment(); final String location = devMode ? "file:///" + appConfig.getDevelopmentProjectRoot() + "myapp/src/" : "classpath:/static/"; int cachePeriod = devMode ? 0 : 31556926; // one year boolean useResourceCache = !devMode; registry .addResourceHandler("/static/**") .addResourceLocations(location) .setCachePeriod(cachePeriod) .resourceChain(useResourceCache).addResolver(new VersionResourceResolver().addContentVersionStrategy("/**")); // TODO: remove registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); if (devMode) { // in dev mode, we need access to the Bower components to load less.js registry .addResourceHandler("/bower_components/**") .addResourceLocations("file:///" + appConfig.getDevelopmentProjectRoot() + "frontend-project/bower_components/") .setCachePeriod(cachePeriod) .resourceChain(useResourceCache).addResolver(new VersionResourceResolver().addContentVersionStrategy("/**")); } } {code} The reources that trigger the NPE are all supposed to be loaded by my 'bower_components' folder (I load client code from the FS in development to speed up coding).

    Spring JIRA | 1 year ago | Gabriele Del Prete
    java.lang.NullPointerException: null
  3. 0
    Elasticsearch 1.x and 2.x nodes are not compatible, make sure your setup contains nodes of the same major version.
    via GitHub by dakrone
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
    It is a JDK bug, no workaround currently.
    via GitHub by jroper
  6. 0
    Some of the parametes ar enull

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      null

      at org.springframework.core.io.UrlResource.createRelative()
    2. Spring Core
      UrlResource.createRelative
      1. org.springframework.core.io.UrlResource.createRelative(UrlResource.java:223)[spring-core-4.2.0.RC3.jar:4.2.0.RC3]
      1 frame
    3. Spring MVC
      AbstractResourceResolver.resolveResource
      1. org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:121)[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3]
      2. org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:94)[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3]
      3. org.springframework.web.servlet.resource.PathResourceResolver.resolveResourceInternal(PathResourceResolver.java:78)[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3]
      4. org.springframework.web.servlet.resource.AbstractResourceResolver.resolveResource(AbstractResourceResolver.java:46)[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3]
      5. org.springframework.web.servlet.resource.DefaultResourceResolverChain.resolveResource(DefaultResourceResolverChain.java:57)[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3]
      6. org.springframework.web.servlet.resource.WebJarsResourceResolver.resolveResourceInternal(WebJarsResourceResolver.java:66)[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3]
      7. org.springframework.web.servlet.resource.AbstractResourceResolver.resolveResource(AbstractResourceResolver.java:46)[spring-webmvc-4.2.0.RC3.jar:4.2.0.RC3]
      7 frames