如何确定哪个Xlint选项对应于编译器警告? [英] How to figure out which Xlint option corresponds to a compiler warning?

查看:290
本文介绍了如何确定哪个Xlint选项对应于编译器警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的软件构建使用 -Xlint -Werror 所以我经常遇到破坏我的构建的编译器警告。每隔一段时间我就会遇到一个我需要压制的警告,但总是很难弄清楚哪个 Xlint 选项会抑制我看到的警告。



我会给你一个具体的例子。我最近遇到过:

  [警告] module-info.java:[16,106]模块未找到:
org .bitbucket.cowwoc.requirements.guava

我搜索了JDK 11源代码并发现了此警告消息声明在 /src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties as:

 #0:符号
compiler.err.module.not.found = \
找不到模块:{0}

现在,事实证明这被 -Xlint抑制:-module 但是文档中并不明显。 -Xlint:-export 也有意义。我也曾经遇到过根本无法抑制的警告(这些警告随后被修复)。



而不是诉诸试错,有没有确定的方法来确定哪个 Xlint 选项对应于每条警告信息? JDK源代码中是否有某种映射文件?



UPDATE :我使用的是Maven 3.6.0,maven-compiler-插件3.8.0,JDK 11.0.1

解决方案

一种方法,如果以某种方式你无法访问


My software builds use -Xlint -Werror so I routinely run across compiler warnings that break my build. Every once in a while I run across a warning that I need to suppress, but it's always difficult to figure out which Xlint option suppresses the warning I am seeing.

I'll give you a concrete example. I recently ran across:

[WARNING] module-info.java:[16,106] module not found: 
    org.bitbucket.cowwoc.requirements.guava

I searched the JDK 11 source-code and discovered this warning message declared at /src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties as:

# 0: symbol
compiler.err.module.not.found=\
    module not found: {0}

Now, it turns out that this is suppressed by -Xlint:-module but that's not obvious from the documentation. -Xlint:-export could made sense as well. I've also run across warnings in the past that couldn't be suppressed at all (these were subsequently fixed).

Instead of resorting to trial and error, is there a deterministic way to figure out which Xlint option corresponds to each warning message? Is there some sort of mapping file somewhere in the JDK source codes?

UPDATE: I am using Maven 3.6.0, maven-compiler-plugin 3.8.0, JDK 11.0.1

解决方案

One way to do that, if somehow you're not able to access the online documentation could be using the command

javac --help-extra

This would list out the possible warnings that you could enable/disable. For example from javac 12-ea :

这篇关于如何确定哪个Xlint选项对应于编译器警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆