RFR: 8283870: jdeprscan --help causes an exception when the locale is ja or zh_CN

Koichi Sakata ksakata at openjdk.java.net
Mon Apr 11 05:39:11 UTC 2022


# Summary
Running jdeprscan with --help option causes an exception on any OSs when the locale is ja or zh_CN.

# How to reproduce this issue

$ jdeprscan -J-Duser.language=ja --help
Exception in thread "main" java.lang.IllegalArgumentException: can't parse argument number: dir|jar|class
        at java.base/java.text.MessageFormat.makeFormat(MessageFormat.java:1454)
        at java.base/java.text.MessageFormat.applyPattern(MessageFormat.java:492)
        at java.base/java.text.MessageFormat.<init>(MessageFormat.java:371)
        at java.base/java.text.MessageFormat.format(MessageFormat.java:860)
        at jdk.jdeps/com.sun.tools.jdeprscan.Messages.get(Messages.java:62)
        at jdk.jdeps/com.sun.tools.jdeprscan.Main.printHelp(Main.java:706)
        at jdk.jdeps/com.sun.tools.jdeprscan.Main.run(Main.java:529)
        at jdk.jdeps/com.sun.tools.jdeprscan.Main.call(Main.java:717)
        at jdk.jdeps/com.sun.tools.jdeprscan.Main.main(Main.java:725)
Caused by: java.lang.NumberFormatException: For input string: "dir|jar|class"
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
        at java.base/java.lang.Integer.parseInt(Integer.java:668)
        at java.base/java.lang.Integer.parseInt(Integer.java:786)
        at java.base/java.text.MessageFormat.makeFormat(MessageFormat.java:1452)
        ... 8 more

$ jdeprscan -J-Duser.language=zh -J-Duser.country=CN --help
(Same as above)

Of course, it works well when the locale is anything other than those locales.

# Details
I found **''**{dir|jar|class}**''** in both ja and zh_CN properties files. Doubled single quotes mean a single quote in MessageFormat class, so the class recognizes {dir|jar|class} as a FormatElement and throws the exception. 

I removed extra single quotes.

# Test
It seems there is no test class for it. So I run commands as I mentioned before.

$ jdeprscan -J-Duser.language=ja --help
使用方法: jdeprscan [options] {dir|jar|class} ...

オプション:
        --class-path PATH
        --for-removal
        --full-version
  -? -h --help
  -l    --list
        --release 7|8|9|10|11|12|13|14|15|16|17|18|19
  -v    --verbose
        --version

非推奨APIの使用について各引数をスキャンします。引数には、
パッケージ階層のルートを指定するディレクトリ、JARファイル、
クラス・ファイルまたはクラス名を使用できます。クラス名は、
完全修飾クラス名を使用して指定する必要があります。ネストされた
クラスは$で区切ります。例:

    java.lang.Thread$State

--class-pathオプションは、依存するクラスの解決のための
検索パスを指定します。

--for-removalオプションは、スキャンとリスト化を削除予定で非推奨のAPIに
限定します。リリース値が6、7または8の場合は使用できません。

--full-versionオプションはツールのバージョン文字列の全体を出力します。

--help (-? -h)オプションは、ヘルプ・メッセージ全体を出力します。

--list (-l)オプションは非推奨APIセットを出力します。スキャンは行われないため、
ディレクトリ、JARまたはクラス引数を指定する必要はありません。

--releaseオプションは、スキャンする非推奨APIのセットを提供するJava SE
リリースを指定します。

--verbose (-v)オプションを使用すると、処理中に追加のメッセージを出力できます。

--versionオプションは、簡略化されたツールのバージョン文字列を出力します。

$ jdeprscan -J-Duser.language=zh -J-Duser.country=CN --help
用法:jdeprscan [options] {dir|jar|class} ...

选项:
        --class-path PATH
        --for-removal
        --full-version
  -? -h --help
  -l    --list
        --release 7|8|9|10|11|12|13|14|15|16|17|18|19
  -v    --verbose
        --version

扫描每个参数以了解是否使用了过时的 API。
参数可以是指定程序包分层结构、JAR 文件、
类文件或类名的根的目录。类名必须
使用全限定类名指定,并使用 $ 分隔符
指定嵌套类,例如,

    java.lang.Thread$State

--class-path 选项提供了用于解析从属类的
搜索路径。

--for-removal 选项限制扫描或列出已过时并待删除
的 API。不能与发行版值 6、7 或 8 一起使用。

--full-version 选项输出工具的完整版本字符串。

--help (-? -h) 选项输出完整的帮助消息。

--list (-l) 选项输出一组已过时的 API。不执行扫描,
因此不应提供任何目录、jar 或类参数。

--release 选项指定提供要扫描的已过时 API 集
的 Java SE 发行版。

--verbose (-v) 选项在处理期间启用附加消息输出。

--version 选项输出工具的缩写版本字符串。

$ jdeprscan -J-Duser.language=en --help                    
Usage: jdeprscan [options] {dir|jar|class} ...

options:
        --class-path PATH
        --for-removal
        --full-version
  -? -h --help
  -l    --list
        --release 7|8|9|10|11|12|13|14|15|16|17|18|19
  -v    --verbose
        --version

Scans each argument for usages of deprecated APIs. An argument
may be a directory specifying the root of a package hierarchy,
a JAR file, a class file, or a class name. The class name must be
specified using a fully qualified class name using the $ separator
character for nested classes, for example,

    java.lang.Thread$State

The --class-path option provides a search path for resolution
of dependent classes.

The --for-removal option limits scanning or listing to APIs that are
deprecated for removal. Cannot be used with a release value of 6, 7, or 8.

The --full-version option prints out the full version string of the tool.

The --help (-? -h) option prints out a full help message.

The --list (-l) option prints out the set of deprecated APIs. No scanning is done,
so no directory, jar, or class arguments should be provided.

The --release option specifies the Java SE release that provides the set
of deprecated APIs for scanning.

The --verbose (-v) option enables additional message output during processing.

The --version option prints out the abbreviated version string of the tool.

-------------

Commit messages:
 - Remove unnecessary single quotes

Changes: https://git.openjdk.java.net/jdk/pull/8174/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=8174&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8283870
  Stats: 2 lines in 2 files changed: 0 ins; 0 del; 2 mod
  Patch: https://git.openjdk.java.net/jdk/pull/8174.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/8174/head:pull/8174

PR: https://git.openjdk.java.net/jdk/pull/8174


More information about the core-libs-dev mailing list