Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3B53B104D4 for ; Wed, 11 Sep 2013 15:08:40 +0000 (UTC) Received: (qmail 94587 invoked by uid 500); 11 Sep 2013 15:08:38 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 94521 invoked by uid 500); 11 Sep 2013 15:08:38 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 94512 invoked by uid 99); 11 Sep 2013 15:08:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Sep 2013 15:08:38 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of arvids.grabovskis@gmail.com designates 209.85.128.180 as permitted sender) Received: from [209.85.128.180] (HELO mail-ve0-f180.google.com) (209.85.128.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Sep 2013 15:08:32 +0000 Received: by mail-ve0-f180.google.com with SMTP id jz11so5938000veb.11 for ; Wed, 11 Sep 2013 08:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=idB3BMUHx4xsT8W/8BUkqiQQnDKlz7iUTP4BOGUoqI4=; b=VGFg9+j4+UbPiiPwrGrt/JWgDzzLHezRayBQnPVpjP8P8D/xlQ/RRXxCXVgO7299xU 0nnpv53YQe/8RSyGNNiT7cKkH3cmJKRJ2s/UDCrlVkf4i0ZMFyml7x9MAfW4dgVDDVOO rh11UpfAZLVn9SGDMIDCuvC9+P7ldyfUr3NXnvfw/D20Qbt4Wh0B1GSvreOFKY+pBgKS JhR6NzA1GuyR/CzTXBooYOpF/DsoAoMpc6FgaKVjqC5zl4sUH9cnN8cR3IpzX5HBGg7f mpALkOae43fGr/QsnVrJrtAcuw+vPiNTpZigKVCY0YBaiFQ4q1vYKAi+JR4ZdMNGs8gd IQUQ== X-Received: by 10.58.161.116 with SMTP id xr20mr1698375veb.2.1378912090317; Wed, 11 Sep 2013 08:08:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.58.29.131 with HTTP; Wed, 11 Sep 2013 08:07:29 -0700 (PDT) In-Reply-To: References: From: =?UTF-8?Q?Arv=C4=ABds_Grabovskis?= Date: Wed, 11 Sep 2013 18:07:29 +0300 Message-ID: Subject: Re: NullPointerException for conditions in compiled JSPs To: Tomcat Developers List Content-Type: multipart/mixed; boundary=047d7b6dcc9651e9c104e61cfdb4 X-Virus-Checked: Checked by ClamAV on apache.org --047d7b6dcc9651e9c104e61cfdb4 Content-Type: multipart/alternative; boundary=047d7b6dcc9651e9bc04e61cfdb2 --047d7b6dcc9651e9bc04e61cfdb2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2013/9/11 Konstantin Kolinko > 2013/9/11 Arv=C4=ABds Grabovskis : > > Hi, > > > > If JSP includes a line "Hello,world!" > > where "nonExisting" is attribute that does not exist, then > > NullPointerException will be thrown. The cause is at > > > http://svn.apache.org/repos/asf/tomcat/trunk/java/org/apache/jasper/compi= ler/JspUtil.java > > at > > line #421 which generates something like: > > ((java.lang.Boolean) > > > org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${nonExist= ing}", > > java.lang.Boolean.class, > (javax.servlet.jsp.PageContext)_jspx_page_context, > > null, false)).booleanValue() > > > > The result of proprietaryEvaluate() is null (because of EL 3.0 changes > > regarding coercing), hence calling booleanValue() will throw NPE. The > > latest changes in EL specification does require guarding against such > null > > pointer access (otherwise it will break lots of existing applications).= I > > really hope that this is not intended behavior. > > > > Double checked the existence of error with Tomcat v8.0.0-RC1 (the same > > problem affects the Glassfish v4, but they have a forked version of JSP= C > > > > 1. Why does it try to convert to "boolean" and not to "Boolean"? > > 2. Yes, a null cannot be converted to primitive boolean value, so an > NPE is the correct behaviour here. So the generated code is correct. > > So the question is why EL expression "${nonExisting}" or "${null}" was > not evaluated to Boolean.FALSE. > > What version of JSTL are you using? > Are you sure that you are using EL-aware versions of the tags > (JSTL 1.1+) instead of older JSTL 1.0 ones? > > What are the steps to reproduce the issue on a clear installation? > What is your version of Tomcat? > What is you stacktrace? > > > Best regards, > Konstantin Kolinko > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org > For additional commands, e-mail: dev-help@tomcat.apache.org > > Konstantin, 1. Manual unboxing does solve potential NPE problems in other parts (where auto-unboxing would throw NPE)... so this is not the real problem... imho. 2. As far as I understand, this is direct result of incompatibility between EL 3.0 ( http://download.oracle.com/otndocs/jcp/el-3_0-fr-eval-spec/index.html) and 2.2 as stated in EL spec this is intended behavior of EL. Here's the citation (Section A.4): "The default coercion for nulls to non-primitive types (except String) returns nulls. For instance, a null coerced to Boolean now returns a null, while a null coerced to boolean returns false." Environment: * JSTL 1.2+ * Tomcat version 8.0.0-RC1 (as previously stated) * JDK 1.7.0_21 I also added a demo application (I hope that mail client won't block it) - just drop it in fresh Tomcat v8 and you'll get the error. here's the stack trace: java.lang.NullPointerException org.apache.jsp.index_jsp._jspx_meth_c_005fif_005f0(index_jsp.java:109) org.apache.jsp.index_jsp._jspService(index_jsp.java:81) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:= 432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:91) -- Arv=C4=ABds --047d7b6dcc9651e9bc04e61cfdb2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
2013/9/11 Konstantin Kolinko <knst.kolinko@gmail.com= >
2013/9/11 Arv=C4=ABds Grabovskis <arvids.grabovskis@gmail.com>:
> Hi,
>
> If JSP includes a line "<c:if test=3D"${nonExisting}"= ;>Hello,world!</c:if>"
> where "nonExisting" is attribute that does not exist, then > NullPointerException will be thrown. The cause is at
> http://svn.apache.org/rep= os/asf/tomcat/trunk/java/org/apache/jasper/compiler/JspUtil.java
> at
> line #421 which generates something like:
> ((java.lang.Boolean)
> org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${= nonExisting}",
> java.lang.Boolean.class, (javax.servlet.jsp.PageContext)_jspx_page_con= text,
> null, false)).booleanValue()
>
> The result of proprietaryEvaluate() is null (because of EL 3.0 changes=
> regarding coercing), hence calling booleanValue() will throw NPE. The<= br> > latest changes in EL specification does require guarding against such = null
> pointer access (otherwise it will break lots of existing applications)= . I
> really hope that this is not intended behavior.
>
> Double checked the existence of error with Tomcat v8.0.0-RC1 (the same=
> problem affects the Glassfish v4, but they have a forked version of JS= PC
>

1. Why does it try to convert to "boolean" and not to= "Boolean"?

2. Yes, a null cannot be converted to primitive boolean value, so an
NPE is the correct behaviour here. So the generated code is correct.

So the question is why EL expression "${nonExisting}" or "${= null}" was
not evaluated to Boolean.FALSE.

What version of JSTL are you using?
Are you sure that you are using EL-aware versions of the tags
(JSTL 1.1+) instead of older JSTL 1.0 ones?

What are the steps to reproduce the issue on a clear installation?
What is your version of Tomcat?
What is you stacktrace?


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Konstantin,

1= . Manual unboxing does solve potential NPE problems in other parts (where a= uto-unboxing would throw NPE)... so this is not the real problem... imho.

2. As far as I understand, this is direct result = of incompatibility between EL 3.0 (http://download= .oracle.com/otndocs/jcp/el-3_0-fr-eval-spec/index.html) and 2.2 as stat= ed in EL spec this is intended behavior of EL. Here's the citation (Sec= tion A.4):
"The default coercion for nulls to non-primitive types (except St= ring) returns=C2=A0
nulls. For instance, a null coerced to Boolea= n now returns a null, while a=C2=A0
null coerced to boolean retur= ns false."

Environment:
* JSTL 1.2+
* Tomc= at version 8.0.0-RC1 (as previously stated)
* JDK 1.7.0_21
<= div>
I also added a demo application (I hope that mail client= won't block it) - just drop it in fresh Tomcat v8 and you'll get t= he error.

here's the stack trace:
java.lang.NullPoi= nterException
org.apache.jsp.index_jsp._jspx_meth_c_005fif_005f0(index_jsp.java:109)
org.apache.jsp.index_jsp.= _jspService(index_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:7= 0)
javax.servlet.http.HttpSe= rvlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServ= letWrapper.java:432)
org.apache.jasper.servlet= .JspServlet.serviceJspFile(JspServlet.java:403)
org.apache.jasper.servlet.JspServlet.service(Js= pServlet.java:347)
javax.servlet.http.HttpSe= rvlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilt= er.java:91)

-- Arv=C4=ABds<= /div>
--047d7b6dcc9651e9bc04e61cfdb2-- --047d7b6dcc9651e9c104e61cfdb4 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org --047d7b6dcc9651e9c104e61cfdb4--