Suppressing Java unchecked warnings in JSP files

為{幸葍}努か 提交于 2020-01-30 04:14:37

问题


I have a legacy webapp which uses jstl and Struts 1 tags. When I pre-compile the JSP files with Java 5/6, the jstl and Struts 1 tags throw warnings about "unchecked or unsafe operations". For example, if I use the following tag:

<%@ page import="/anotherpage.inc" %>

The following warning is thrown:

[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.

If I recompile with -Xlint:unchecked, I get details about the internal working of the offending JSP tag library. I would like to suppress all unchecked operation warnings. I thought that using -Xlint:-unchecked would suppress the warnings, but it did not.

How do I suppress these warnings when compiling my JSP pages? It would not be practical to re-code the JSP tag libraries or update a thousand JSP pages. I'm looking for a compiler flag to globally disable the warning so I can see all warnings except for unchecked warnings. Thanks!


回答1:


Those messages are a (mandatory for JDK >= 1.5) note, not a warning.

compiler.note.unchecked.plural=\
    Some input files use unchecked or unsafe operations.

The default compiler behaviour is the same as with -Xlint:-unchecked.

With -Xlint:unchecked you turn the warning on, reporting each instance.

compiler.warn.unchecked.assign=\
    [unchecked] unchecked assignment: {0} to {1}
...

Mandatory notes cannot be disabled individually, they are all disabled with -Xlint:none. Unfortunately, the rest of the warnings are also disabled.

You can check other responses for alternatives, but filtering compiler output messages seems the easiest solution.




回答2:


You are right that

-Xlint:unchecked

does the opposite of what you want, but you can also use

-Xlint:-unchecked

Note the extra "-" in there.

This will disable all warnings about unchecked operations, not just the ones generated by the tag library, but other warnings will still be shown.




回答3:


the best way to disable that warning is to stop using Java code in your JSPs. Start getting used to using JSTL or JSF instead (with custom tag libs as needed).

But with legacy applications you're not going to be able to do that most likely, and you'll just have to live with the warnings. Of course you can add the -nowarn flag to the compiler, but this will disable ALL warnings, not just this one, which may be more than you want.



来源:https://stackoverflow.com/questions/4925708/suppressing-java-unchecked-warnings-in-jsp-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!