webjars / webjars-play

MIT License
80 stars 34 forks source link

Null Pointer exception when overriding default RequireJS config #60

Closed javierfvargas closed 8 years ago

javierfvargas commented 8 years ago

Webjars documentation propose this:

@for(webJarJson <- org.webjars.RequireJS.getSetupJson(routes.WebJarAssets.at("").url).values()) { requirejs.config(@Html(webJarJson.toString)); }

I had to use it @for(webJarJson <- org.webjars.RequireJS.getSetupJson(routes.WebJarAssets.at("").url).values()) { @if( webJarJson != null ){ requirejs.config(@Html(webJarJson.toString)); } }

When running in production mode I got a null pointer exception. It seems that among the values for Json setup some nulls are included and it needs to be checked. I didn't happen to me in previous versions.

jamesward commented 8 years ago

Thanks for the report. Were you able to figure out which WebJar had the null json? Then I can setup a test to catch this.

rjregenold commented 8 years ago

I ran into this also. Here is the output of org.webjars.RequireJS.getSetupJson(routes.WebJarAssets.at("").url).values():

[
  null,
  {
    "paths": {

    },
    "packages": [

    ]
  },
  {
    "paths": {
      "underscore": [
        "\/webjars\/underscorejs\/1.8.3\/underscore",
        "underscore"
      ],
      "underscorejs": [
        "\/webjars\/underscorejs\/1.8.3\/underscore",
        "underscore"
      ]
    },
    "shim": {
      "underscore": {
        "exports": "_"
      },
      "underscorejs": {
        "exports": "_"
      }
    },
    "packages": [

    ]
  },
  {
    "paths": {
      "bootstrap": [
        "\/webjars\/bootstrap\/3.3.6\/js\/bootstrap",
        "js\/bootstrap"
      ],
      "bootstrap-css": [
        "\/webjars\/bootstrap\/3.3.6\/css\/bootstrap",
        "css\/bootstrap"
      ]
    },
    "shim": {
      "bootstrap": [
        "jquery"
      ]
    },
    "packages": [

    ]
  },
  {
    "paths": {
      "validate-js": [
        "\/webjars\/validate.js\/0.8.0\/validate"
      ]
    }
  },
  {
    "paths": {
      "jquery": [
        "\/webjars\/jquery\/1.11.1\/jquery",
        "jquery"
      ]
    },
    "shim": {
      "jquery": {
        "exports": "$"
      }
    },
    "packages": [

    ]
  },
  {
    "paths": {
      "mustache": [
        "\/webjars\/mustachejs\/2.2.1\/mustache",
        "mustache"
      ]
    },
    "packages": [

    ]
  }
]

The relevant part of my build.sbt looks like this:

libraryDependencies ++= Seq(
  // ...

  "org.webjars"              %% "webjars-play"          % "2.4.0-2",
  "org.webjars"               % "bootstrap"             % "3.3.6",
  "org.webjars"               % "underscorejs"          % "1.8.3",
  "org.webjars"               % "mustachejs"            % "2.2.1"
)

Not sure if this is helpful or not. Please let me know if I can provide additional information.

jamesward commented 8 years ago

Thanks @rjregenold. I'm updating the docs now. I could have added methods that were safer. And maybe we will do that at some point. But for now just having correct docs might be sufficient.