- This topic has 16 replies, 6 voices, and was last updated 15 years, 9 months ago by Riyad Kalla.
-
AuthorPosts
-
charl.gerberMemberQuite a few of my JSP’s compile, but generate this warning message:
“Variable out can only be null, it was either set to null or checked for null when last used”.
This typically happens in java code at the beginning of my JSP that doesn’t even reference this variable, eg:
<% String contextPath = request.getContextPath(); int clusterId = -1; try { clusterId = Integer.parseInt(request.getParameter("clusterId")); } catch(Exception e) { } %>
Anyone seen this before and how do I get rid of it? I don’t want to disable the default java compile option for this, as I find it useful in normal java classes. Seems like the JSP generates java code that does an unncessary null check?
Thanks!
Riyad KallaMemberWhich line is it complaining about? Your request.getParameter line can return null, but you can’t checked for it (which is fine cause of the try-catch) but that might be what it’s complaining about.
Also if you go to the MyEclipse menu, go down to INstallation Summary then Installation Details, and paste the result here, that might help me get an idea of what we would do (maybe an upgrade to help).
charl.gerberMemberIt gives the warning where I close my java code, ie, at the %> line.
*** Date: Mon Nov 13 17:14:44 CET 2006
*** System properties:
OS=WindowsXP
OS version=5.1
Java version=1.4.2_12*** MyEclipse details:
MyEclipse Enterprise WorkbenchVersion: 5.0 GA
Build id: 20060805-5.0-GA*** Eclipse details:
MyEclipse Enterprise WorkbenchVersion: 5.0.1 GA
Build id: 20060810-5.0.1-GAEclipse Graphical Editing Framework
Version: 3.2.0.v20060626
Build id: 20060627-0816Eclipse Platform
Version: 3.2.1.r321_v20060921-b_XVA-INSQSyMtx
Build id: M20060921-0945Eclipse RCP
Version: 3.2.1.r321_v20060801-2ekW2BxmcpPUOoq
Build id: M20060921-0945Eclipse Java Development Tools
Version: 3.2.1.r321_v20060905-R4CM1Znkvre9wC-
Build id: M20060921-0945Eclipse Plug-in Development Environment
Version: 3.2.1.r321_v20060823-6vYLLdQ3Nk8DrFG
Build id: M20060921-0945Eclipse Project SDK
Version: 3.2.1.r321_v20060801-tQ1w49KnTArT0FZ
Build id: M20060921-0945Eclipse startup command=-os
win32
-ws
win32
-arch
x86
-launcher
C:\Program Files\eclipse\eclipse.exe
-name
Eclipse
-showsplash
600
-exitdata
c80_80
-product
com.genuitec.myeclipse.product.ide
-vm
C:\WINDOWS\system32\javaw.exe
Riyad KallaMemberHmm, I don’t think an upgrade will help, although our new 5.1 release just came out this morning, but I think this falls under our open feature request to allow more control over validation messages.
charl.gerberMemberI get the same warning with 5.1.
coleb@ctc.comMemberCurrently running:
*** MyEclipse details:
MyEclipse Enterprise Workbench
Version: 5.5.1 GA
Build id: 20070521-5.5.1-GAand receive the same “The variable out can only be null; it was either set to null or checked for null when last used” in all of our scriptlets. Found that moving the “%>” to the end of the previous code line removes the warning. So it seems like it is a false warning and hopefully a very simple correction.
Riyad KallaMemberHey guys I’m trying to reproduce this in 5.5 and 6.0 and I cannot, here is my sample JSP page:
<%@ page language="java" pageEncoding="ISO-8859-1"%> <% String contextPath = request.getContextPath(); int clusterId = -1; try { clusterId = Integer.parseInt(request.getParameter("clusterId")); } catch (Exception e) { } %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <% String contextPath2 = request.getContextPath(); int clusterId2 = -1; try { clusterId2 = Integer.parseInt(request.getParameter("clusterId")); } catch (Exception e) { } %> </body> </html>
CAn you provide me a better example to see this bug in action?
Audun MeltzerMemberThe following is an example code that causes validation warning in my myEclipse 6. I have commented teh exact warning text on the lines that are marked in Eclipse.
Feel free to contact me directly if you need more information regarding this example or my system configuration.
————<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <%@ page contentType="text/html; charset=ISO-8859-1" %> <html> <% session.getAttribute(""); // Null pointer access: The variable session can only be null at this location %> <% String path = ""; %>// Null pointer access: The variable out can only be null at this location <head> </head> <body> <div> <%= path %> </div> </body> </html>
Riyad KallaMemberRESOURCE,
I’m not seeing any warnings or errors on this page, but I *did* have to wrap your // comment in HTML comment tags because it’s in an invalid location:<!-- // Null pointer access: The variable out can only be null at this location -->
other than that, the page is clean. I’m using MyEclipse 6.0 GA
Audun MeltzerMemberHi, thanks for prompt reply!
I did paste the comment lines in just to specify exactly what lines I get the 2 yellow warning triangles. I have also determined that it is the setting “JSP Syntax Validator” under Windows>Preferences>MyEclipse>Validation that determines if these warnings show up.
I am using the following MyEclipse
Version: 6.0.0 GA
Build id: 6.0.0-GA-200708In the “configurations window” I see the following if it is of relevance:
eclipse.buildId=I20070625-1500I hope this is of further help. Is there any other settings or information that is of relevance?
Regards
Knut Fjellheim
Senior project manager
Firstventura AS
Riyad KallaMemberKnut,
Your install and setings all sounds exactly right… I just cannot reproduce the problem with the small code snippet.Maybe you could create a sample project that exhibits the problem and email it to me? (support@genuitec.com ATTN Riyad, with a link to this thread)
Audun MeltzerMemberHi,
I have forwarded a zip’ed archive of a test project that creates the issue in my Eclipse.
I am using version 6.0.0GA/build 6.0.0-GA-200708. However, my coworker seems to not get these issues. He is using MyEclipse version 6.0.0M1 / build 20070629-6.0.0M1. Would you perhaps be able to examine this test code in both environments and see if you find any difference?
Regards
Knut Fjellheim
Senior project manager
Firstventura AS
Riyad KallaMemberKnut,
Thank you for the sample project. I imported it and everything worked as expected, no stray warnings except for the invalid comment in your JSP page.I tried the page in 5.5 and 6.0M1 as well and got the same result, I think there may be something going on with your installation of 6.0.
If you had the time, I’d strongly encourage you to redownload our 6.0 All in One installer, and install it to a new directory and reopen your old workspace, then clean your project and see if everything started acting a bit more smoothly.
J.C. HamlinParticipantVersion: 6.0.1 GA
Build id: 6.0.1-GA-200710
Java: 1.5.0_15-b04I can reproduce both of these problems.The trick is to ensure Java->Compiler->Errors/Warnings->Null pointer access: is set to “Warning”.
The reason you are getting the warning in the weird spot is because you have a newline before the tag that closes your script tag %> and that generates an out.write(“\r\n”); in the _jsp.java file generated by the JSP compiler.
However, you can easily see the real problems if you do put an out.println(“Hello World”); in your script. out will be seen as a Null access by the JDT compiler. We have very strict warnings levels turn on (almost every one turned on). I would like to see MyEclipse generate these JSP pages and have them pass all of Eclipse’s JDT compiler’s most strict level out output.
I think the reason is that MyEclipse is generating and compliing the JSP through the JDT compiler, but is only creating an out variable, but not initializing it to a JspWriter. In production Jasper (or whatever your JSP compiler is) will take that JSP page and generate the following which intializes out (and pageContext and all the other JSP variables that if you try to use you’ll get a Null pointer warning). I dont think MyEclipse is generating the same stub when sending to the JDT compiler, and thus we see the warning.
<%@page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%> <% out.println("hello"); %>
generates:
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html; charset=utf-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.apache.jasper.runtime.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("\r\n"); out.write("\r\n"); out.println("hello"); out.write('\r'); out.write('\n'); } catch (Throwable t) { if (!(t instanceof SkipPageException)){ out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
I have a project I can upload/send that demonstrates the problem.
This problem as been around for years. I’d like to see this one finally fixed!
-J.C.
Riyad KallaMemberJ.C. first let me thank you for such a detailed replied, it took me all of 2 seconds to find the problem. Confirmed with management that this will be fixed in MyEclipse 7.0 (high priority work on 6.5 is taking the last bit of precedence). 7.0 is not that far off though, it will be the first version of MyEclipse ontop of Ganymede which we want to get out a month or so after the Ganymede release for testing.
Thank you guys for your patience.
-
AuthorPosts