You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pmd check AFTIPCSelectorProvider.java --aux-classpath=junixsocket-selftest-2.6.2-jar-with-dependencies.jar --use-version=java-8 -f text -R pmd-ruleset.xml
Warning shown:
AFTIPCSelectorProvider.java:128: UseDiamondOperator: Explicit type arguments can be replaced by a diamond: `new AFTIPCSocketPair<>(s1, s2)`
After changing to the diamond operator, compilation for Java 8 fails with:
[ERROR] .../AFTIPCSelectorProvider.java:[48,36] cannot infer type arguments for org.newsclub.net.unix.AFAddressFamilyConfig<A>
reason: '<>' with anonymous inner classes is not supported in -source 8
(use -source 9 or higher to enable '<>' with anonymous inner classes)
The text was updated successfully, but these errors were encountered:
I cannot reproduce this. When I try with PMD 7 snapshot (built locally), the rule behaves as expected:
# java 8
$ sandbox/pmd-bin-7.0.0-SNAPSHOT/bin/pmd check -d ~/Downloads/AFTIPCSelectorProvider.java --aux-classpath ~/Downloads/junixsocket-selftest-2.6.2-jar-with-dependencies.jar -R category/java/codestyle.xml/UseDiamondOperator --no-progress --use-version java-8 --no-cache
[main] INFO net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand - Log level is at INFO
/home/clem/Downloads/AFTIPCSelectorProvider.java:128: UseDiamondOperator: Explicit type arguments can be replaced by a diamond: `new AFTIPCSocketPair<>(s1, s2)`# java 9
$ sandbox/pmd-bin-7.0.0-SNAPSHOT/bin/pmd check -d ~/Downloads/AFTIPCSelectorProvider.java --aux-classpath ~/Downloads/junixsocket-selftest-2.6.2-jar-with-dependencies.jar -R category/java/codestyle.xml/UseDiamondOperator --no-progress --use-version java-9 --no-cache
[main] INFO net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand - Log level is at INFO
/home/clem/Downloads/AFTIPCSelectorProvider.java:48: UseDiamondOperator: Explicit type arguments can be replaced by a diamond: `new AFAddressFamilyConfig<>()`/home/clem/Downloads/AFTIPCSelectorProvider.java:128: UseDiamondOperator: Explicit type arguments can be replaced by a diamond: `new AFTIPCSocketPair<>(s1, s2)`
I got the same results with the released binary for PMD7 RC3 (there has been no changes to the rule since).
Affects PMD Version:
7.0.0-SNAPSHOT
Rule:
UseDiamondOperator
Description:
A class member that initializes an anonymous inner class with generics must not use the diamond operator (for code that targets Java 8).
Code Sample demonstrating the issue:
from https://github.com/kohlschutter/junixsocket/blob/72110d0/junixsocket-tipc/src/main/java/org/newsclub/net/unix/tipc/AFTIPCSelectorProvider.java
Expected outcome:
PMD reports a violation at the line marked with "// here"", but that's wrong. That's a false positive.
Running PMD through: CLI
Only occurs with "aux-classpath" set. Download junixsocket-selftest-2.6.2-jar-with-dependencies.jar to reproduce. Use attached pmd-ruleset.xml.zip
pmd check AFTIPCSelectorProvider.java --aux-classpath=junixsocket-selftest-2.6.2-jar-with-dependencies.jar --use-version=java-8 -f text -R pmd-ruleset.xml
Warning shown:
After changing to the diamond operator, compilation for Java 8 fails with:
The text was updated successfully, but these errors were encountered: