如何抑制有关 Sun 专有 API 的 java 编译器警告

发布于 2024-07-27 14:26:34 字数 192 浏览 3 评论 0原文

我正在使用 sun.misc.BASE64Encoder 包中的encode() 方法。 如何抑制它生成的编译器警告?

sun.misc.BASE64Encoder 是 Sun 专有 API,可能会在

中删除

并且作为后续操作,为什么我在 Eclipse 中看不到此警告?

I'm using the encode() method from the sun.misc.BASE64Encoder package. How do I suppress the compiler warnings that it generates?

sun.misc.BASE64Encoder is Sun proprietary API and may be removed in

And as a followup, why don't I see this warning in Eclipse?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

诗笺 2024-08-03 14:26:34

有一种完全没有记录的方法可以抑制 sun 专有 API 警告!
-XDignore.symbol.file 添加到 javac 命令行。

我在 https://bugs.java.com/bugdatabase/view_bug?bug_id= 找到了这个6476630(一直滚动到最后一条评论)。 我们都需要对添加最后一条评论的“xfournet”有善意的想法!

There is a totally undocumented way to suppress the sun proprietary API warnings!
Add -XDignore.symbol.file to the javac command line.

I found this at https://bugs.java.com/bugdatabase/view_bug?bug_id=6476630 (scroll all the way to the very last comment). We all need to think kind thoughts about "xfournet" who added that last comment!

糖粟与秋泊 2024-08-03 14:26:34

您可以切换到不同的 Base64 实现,例如 http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html 这是 Apache commons 包的一部分,您可能已经将其包含在类路径中,或 http://iharder.sourceforge.net/current/java/base64/ 其中如果您不希望路径上有另一个 Jar,您可以直接采用实现并粘贴在源代码树中。

You could switch to a different Base64 implementation, e.g., http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html which is part of the Apache commons packages, which you might already have included in your classpath, or http://iharder.sourceforge.net/current/java/base64/ which you could just take the implementation and stick in your source tree if you don't want another Jar on the path.

江挽川 2024-08-03 14:26:34

Eclipse 确实有一个设置(应该)选择它,请参见 Eclipse 3.1 发行说明

首选项 → Java → 编译器 → 错误/警告 → 已弃用和受限制的 API → 禁止/不鼓励的参考

(以及允许项目特定的项目属性页面覆盖此设置)

Eclipse does have a setting which (should) pick this up, see e.g. the desciption in the Eclipse 3.1 release notes:

Preferences → Java → Compiler → Errors/Warnings → Deprecated And Restricted API → Forbidden/Discouraged Reference

(and the project properties page to allow project-specific overrides of this setting)

您无法关闭它们,Eclipse 只是为您过滤它们(如果被告知这样做)。

Linux 上的快速临时修复:

javac *.java 2>&1 | pcregrep -v -M ".*Sun proprietary API.*\n.*\n.*\^"

2>&1 ... 将 STDERR 放入 STDOUT,因此管道“|” 可以工作

pcregrep 可能存在也可能不存在于您的系统上 - 如果没有,请使用您的软件包实用程序(例如在 Debian、Ubuntu 等上:“sudo apt-get install pcregrep”)

该表达式搜索“Sunproprietary API”警告和下面两行(包含该行和指示该行中错误位置的“^”)。

我留下“XY 警告”。 在最后排队,以免我忘记有警告;o)
请注意,如果您还有其他警告,则报告的数字当然不正确:o)

另请注意,标准“grep”也不起作用,因为它不能跨越多行。

You can't switch them off, Eclipse simply filters them for you (if told to do so).

Quick interim fix on Linux:

javac *.java 2>&1 | pcregrep -v -M ".*Sun proprietary API.*\n.*\n.*\^"

2>&1 ... puts STDERR into STDOUT, so the pipeline "|" will work

pcregrep might or might not be present on your system - if not, use your package utility (e.g. on Debian, Ubuntu etc: "sudo apt-get install pcregrep")

The expression searches for the "Sun proprietary API" warning and the following two lines (containing the line and the "^" indicating the position of the error in the line).

I leave the "XY warnings." line in at the end, lest I forget there were warnings ;o)
Note that if you have other warnings as well, the number reported there will of course not be correct :o)

NOTE also that standard "grep" does not work as well, because it can't span multiple lines.

他是夢罘是命 2024-08-03 14:26:34

如果您了解使用专有 API 的固有问题并决定无论如何都要这样做,并且您使用的是 Maven,那么您可能有兴趣将以下内容添加到您的 pom.xml 文件中:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <compilerArgument>-XDignore.symbol.file</compilerArgument>
    </configuration>
</plugin>

If you understand the inherent problems with using a proprietary API and decide to do it anyway, and if you are using maven, you might be interested in adding the following to your pom.xml file:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <compilerArgument>-XDignore.symbol.file</compilerArgument>
    </configuration>
</plugin>
暗地喜欢 2024-08-03 14:26:34

如果你使用的是jdk 1.8那么你可以使用下面的

java.util.Base64

If you are using jdk 1.8 then you can use the below

java.util.Base64
完美的未来在梦里 2024-08-03 14:26:34

将调用封装在类中,并将其放置在类路径上的库 jar 中。 然后,仅在重新编译该库时才会显示警告。

Encapsulate the call in a class which you place in a library jar on your classpath. Then the warning only shows when that library is recompiled.

情定在深秋 2024-08-03 14:26:34

javac 选项 -Xlint:unchecked 确实可以解决问题:它禁用警告,请参阅 javac 手册 了解详细信息

The javac option -Xlint:unchecked does do the trick: it disables the warnings, see the javac manual for details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文