Eclipse: Removing warnings like "Unnecessary Dropping from Object to Object"

I have a Spring 4.0.9 MVC application using JSP as the view technology and Maven 3.2.5 for build management. And I am using Eclipse 4.4.1 for development and Tomcat 7.0.57 to run my application.

In JSP, I want to use EL expression ${pageContext.request.contextPath}

to refer to the current request path. But Eclipse is giving me an error:

javax.servlet.jsp.JspException cannot be resolved to a type

I added the following Maven dependency:

<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.2</version>
  <scope>provided</scope>
</dependency>

      

and the error goes away, but now I am getting several new types of warnings. Wherever I use the EL expression above, Eclipse says:

The declared exception IOException is not actually thrown by the method _elExpression7505() from type __2F_myproject_2F_src_2F_main_2F_webapp_2F_WEB_2D_INF_2F_views_2F_page_2E_jsp

And everywhere I use the Spring tag form:label

that it tells me:

Unnecessary cast from Object to Object

Does anyone know how to get rid of these warnings? Should I use other Maven dependencies? (I've also included javax.servlet-api 3.0.1, jstl 1.2 and many more)

Edit: I don't want to globally ignore this type of warnings for all Java files. For me, this would be more of a workaround than a real solution.

+3


source to share


2 answers


Fortunately, Eclipse has a place to edit warnings / errors:

Project Properties -> Java Compiler -> Errors/Warnings

      

There is a nice search box that you can use to track down the error / warning installation you want to edit (for example, you could search for "Unnecessary Cast"). In the dropdown to the right of the displayed entry, you can select Ignore

. Click Apply, rebuild the project and you should get rid of the warnings that you wanted to go away.

You will need to set the following warnings to "ignore":



  • Unnecessary cast or 'instanceof' operation

  • Unnecessary declaration of thrown exception

See this help page for reference.

Edit: According to this answer on Stackoverflow, you can enable folders to check for warnings. I haven't tested this myself, so this is a long shot.

+2


source


At the top of your JSP, you can include the following:

<%! @SuppressWarnings("cast") %>

      



This will prevent the "eclipse object exclusion warning" from showing.

+2


source







All Articles