Fix NullPointerException, add missing JavaScript literal binders and correctly convert null in binders #3514
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First of all: I created a very simple project to demonstrate the bugs I stumpled into using Play 2.3.5. (After running
activator new routesTest play-javaI only added some basic routes inconf/routesand added the accompanying actions inapp/controllers/Application.javawith this commit).Now Step-by-Step:
1) There are some JavaScript literal binders missing
Have a look at the routes file. When you want to compile this routes file you get following errors:
and
and
(You would also get an error for the missing UUID JavaScript literal binder - I already submitted the PR #3508 for this missing UUID JavaScript literal binder yesterday)
So with this PR I added the missing JavaScript literal binders for
play.libs.F.Option,java.lang.Longandjava.lang.Boolean.2) NullPointerExceptions occur when assigning
nullas a default to Java Types in a routeAfter implementing the missing binders (including #3508), the project will now fail with a
NullPointerExceptionin the already existingjava.lang.IntegerJavaScript literal binder when assigningnullas a default in a route (see line 13). If you have a look at my fix, you will see that's because.toStringis called without checking if the default value is null before. (FYI: To actually get thisNullPointerExceptionyou actually have to call the JavaScript route like in line 53 of the Application.java. If you don't call it you won't experience the NullPointerException).3) When assigning null as a default to a String in a route, it gets converted to a JavaScript "null" String instead of a Javascript null value
See line 9 in the routes file. Without this PR following JavaScript is generated for JavaScript reverse routing (in case you run my test project you could just have a look at
/assets/routes.js):With my PR it correctly becomes:
Please also backport this PR and #3508 to 2.3.x (be aware to rename JavascriptLiteral to JavascriptLitteral for the 2.3.x branch).
Thanks!