Suppressing Java unchecked warnings in JSP files

后端 未结 3 878
情书的邮戳
情书的邮戳 2021-01-17 14:13

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 unsa

相关标签:
3条回答
  • 2021-01-17 14:39

    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.

    0 讨论(0)
  • 2021-01-17 14:43

    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.

    0 讨论(0)
  • 2021-01-17 15:02

    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.

    0 讨论(0)
提交回复
热议问题