diff --git a/.all-contributorsrc b/.all-contributorsrc index 717e21a7d5..66cd053fa8 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6621,6 +6621,15 @@ "contributions": [ "code" ] + }, + { + "login": "VoidxHoshi", + "name": "LaLucid", + "avatar_url": "https://avatars.githubusercontent.com/u/55886143?v=4", + "profile": "https://github.com/VoidxHoshi", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index c0c5daead0..b252c1d257 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -395,552 +395,553 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Koen Van Looveren

πŸ›
Kris Scheibe

πŸ’» πŸ›
Kunal Thanki

πŸ› +
LaLucid

πŸ’»
Larry Diamond

πŸ’» πŸ›
Lars Knickrehm

πŸ›
Leo Gutierrez

πŸ› -
LiGaOg

πŸ’» +
LiGaOg

πŸ’»
Lintsi

πŸ›
Linus Fernandes

πŸ›
Lixon Lookose

πŸ›
Logesh

πŸ›
Lorenzo Gabriele

πŸ›
LoΓ―c Ledoyen

πŸ› -
Lucas Silva

πŸ› +
Lucas Silva

πŸ›
Lucas Soncini

πŸ’» πŸ›
Lukasz Slonina

πŸ›
Lukebray

πŸ›
Lyor Goldstein

πŸ›
MCMicS

πŸ›
Macarse

πŸ› -
Machine account for PMD

πŸ’» +
Machine account for PMD

πŸ’»
Maciek Siemczyk

πŸ›
Maikel Steneker

πŸ’» πŸ›
Maksim Moiseikin

πŸ›
Manfred Koch

πŸ›
Manuel Moya Ferrer

πŸ’» πŸ›
Manuel Ryan

πŸ› -
Marat Vyshegorodtsev

πŸ› +
Marat Vyshegorodtsev

πŸ›
Marcel HΓ€rle

πŸ›
Marcello Fialho

πŸ›
Marcin Rataj

πŸ›
Mark Adamcin

πŸ›
Mark Hall

πŸ’» πŸ›
Mark Kolich

πŸ› -
Mark Pritchard

πŸ› +
Mark Pritchard

πŸ›
Markus Rathgeb

πŸ›
Marquis Wang

πŸ›
Martin Feldsztejn

πŸ›
Martin Lehmann

πŸ›
Martin Spamer

πŸ›
Martin TarjΓ‘nyi

πŸ› -
MatFl

πŸ› +
MatFl

πŸ›
Mateusz Stefanski

πŸ›
Mathieu Gouin

πŸ›
MatiasComercio

πŸ’» πŸ›
Matt Benson

πŸ›
Matt De Poorter

πŸ›
Matt Harrah

πŸ› -
Matt Nelson

πŸ› +
Matt Nelson

πŸ›
Matthew Amos

πŸ›
Matthew Duggan

πŸ›
Matthew Hall

πŸ›
MatΓ­as Fraga

πŸ’» πŸ›
Maxime Robert

πŸ’» πŸ›
MetaBF

πŸ› -
Michael

πŸ› +
Michael

πŸ›
Michael Bell

πŸ›
Michael Bernstein

πŸ›
Michael Clay

πŸ›
Michael Dombrowski

πŸ›
Michael Hausegger

πŸ›
Michael Hoefer

πŸ› -
Michael MΓΆbius

πŸ› +
Michael MΓΆbius

πŸ›
Michael N. Lipp

πŸ›
Michael Pellegrini

πŸ›
Michal Kordas

πŸ›
MichaΕ‚ Borek

πŸ›
MichaΕ‚ KuliΕ„ski

πŸ›
Miguel NΓΊΓ±ez DΓ­az-Montes

πŸ› -
Mihai Ionut

πŸ› +
Mihai Ionut

πŸ›
Mirek Hankus

πŸ›
Mladjan Gadzic

πŸ›
MrAngry52

πŸ›
Muminur Choudhury

πŸ›
Mykhailo Palahuta

πŸ’» πŸ›
Nagendra Kumar Singh

πŸ› -
Nahuel Barrios

πŸ› +
Nahuel Barrios

πŸ›
Nathan Braun

πŸ›
Nathan Reynolds

πŸ›
Nathan Reynolds

πŸ›
NathanaΓ«l

πŸ›
Nazdravi

πŸ›
Neha-Dhonde

πŸ› -
Nicholas Doyle

πŸ› +
Nicholas Doyle

πŸ›
Nick Butcher

πŸ›
Nico Gallinal

πŸ›
Nicola Dal Maso

πŸ›
Nicolas Filotto

πŸ’»
Nikita Chursin

πŸ›
Niklas Baudy

πŸ› -
Nikolas Havrikov

πŸ› +
Nikolas Havrikov

πŸ›
Nilesh Virkar

πŸ›
Nimit Patel

πŸ›
Niranjan Harpale

πŸ›
Noah Sussman

πŸ›
Noah0120

πŸ›
Noam Tamim

πŸ› -
Noel Grandin

πŸ› +
Noel Grandin

πŸ›
Olaf Haalstra

πŸ›
Oleg Pavlenko

πŸ›
Oleksii Dykov

πŸ’»
Oliver Eikemeier

πŸ›
Olivier Parent

πŸ’» πŸ›
Ollie Abbey

πŸ’» πŸ› -
OverDrone

πŸ› +
OverDrone

πŸ›
Ozan Gulle

πŸ’» πŸ›
PUNEET JAIN

πŸ›
Parbati Bose

πŸ›
Paul Berg

πŸ›
Pavel Bludov

πŸ›
Pavel Mička

πŸ› -
Pedro Nuno Santos

πŸ› +
Pedro Nuno Santos

πŸ›
Pedro Rijo

πŸ›
Pelisse Romain

πŸ’» πŸ“– πŸ›
Pete Davids

πŸ›
Peter Bruin

πŸ›
Peter Chittum

πŸ’» πŸ›
Peter Cudmore

πŸ› -
Peter Kasson

πŸ› +
Peter Kasson

πŸ›
Peter Kofler

πŸ›
Pham Hai Trung

πŸ›
Philip Graf

πŸ’» πŸ›
Philip Hachey

πŸ›
Philippe Ozil

πŸ›
Phinehas Artemix

πŸ› -
Phokham Nonava

πŸ› +
Phokham Nonava

πŸ›
Piotr SzymaΕ„ski

πŸ›
Piotrek Ε»ygieΕ‚o

πŸ’» πŸ›
Pranay Jaiswal

πŸ›
Prasad Kamath

πŸ›
Prasanna

πŸ›
Presh-AR

πŸ› -
Puneet1726

πŸ› +
Puneet1726

πŸ›
Rafael CortΓͺs

πŸ›
RaheemShaik999

πŸ›
RajeshR

πŸ’» πŸ›
Ramachandra Mohan

πŸ›
Raquel Pau

πŸ›
Ravikiran Janardhana

πŸ› -
Reda Benhemmouche

πŸ› +
Reda Benhemmouche

πŸ›
Renato Oliveira

πŸ’» πŸ›
Rich DiCroce

πŸ›
Riot R1cket

πŸ›
Rishabh Jain

πŸ›
RishabhDeep Singh

πŸ›
Robbie Martinus

πŸ’» πŸ› -
Robert Henry

πŸ› +
Robert Henry

πŸ›
Robert Painsi

πŸ›
Robert Russell

πŸ›
Robert SΓΆsemann

πŸ’» πŸ“– πŸ“’ πŸ›
Robert Whitebit

πŸ›
Robin Richtsfeld

πŸ›
Robin Stocker

πŸ’» πŸ› -
Robin Wils

πŸ› +
Robin Wils

πŸ›
RochusOest

πŸ›
Rodolfo Noviski

πŸ›
Rodrigo Casara

πŸ›
Rodrigo Fernandes

πŸ›
Roman Salvador

πŸ’» πŸ›
Ronald Blaschke

πŸ› -
RΓ³bert Papp

πŸ› +
RΓ³bert Papp

πŸ›
Saikat Sengupta

πŸ›
Saksham Handu

πŸ›
Saladoc

πŸ›
Salesforce Bob Lightning

πŸ›
Sam Carlberg

πŸ›
Satoshi Kubo

πŸ› -
Scott Kennedy

πŸ› +
Scott Kennedy

πŸ›
Scott Wells

πŸ› πŸ’»
Scrsloota

πŸ’»
Sebastian BΓΆgl

πŸ›
Sebastian Schuberth

πŸ›
Sebastian Schwarz

πŸ›
Sergey Gorbaty

πŸ› -
Sergey Kozlov

πŸ› +
Sergey Kozlov

πŸ›
Sergey Yanzin

πŸ’» πŸ›
Seth Wilcox

πŸ’»
Shubham

πŸ’» πŸ›
Simon Xiao

πŸ›
Srinivasan Venkatachalam

πŸ›
Stanislav Gromov

πŸ› -
Stanislav Myachenkov

πŸ’» +
Stanislav Myachenkov

πŸ’»
Stefan Birkner

πŸ›
Stefan Bohn

πŸ›
Stefan Endrullis

πŸ›
Stefan KlΓΆss-Schuster

πŸ›
Stefan Wolf

πŸ›
Stephan H. Wissel

πŸ› -
Stephen

πŸ› +
Stephen

πŸ›
Stephen Friedrich

πŸ›
Steve Babula

πŸ’»
Stexxe

πŸ›
Stian LΓ₯gstad

πŸ›
StuartClayton5

πŸ›
Supun Arunoda

πŸ› -
Suren Abrahamyan

πŸ› +
Suren Abrahamyan

πŸ›
SwatiBGupta1110

πŸ›
SyedThoufich

πŸ›
Szymon Sasin

πŸ›
T-chuangxin

πŸ›
TERAI Atsuhiro

πŸ›
TIOBE Software

πŸ’» πŸ› -
Taylor Smock

πŸ› +
Taylor Smock

πŸ›
Techeira DamiΓ‘n

πŸ’» πŸ›
Ted Husted

πŸ›
TehBakker

πŸ›
The Gitter Badger

πŸ›
Theodoor

πŸ›
Thiago Henrique HΓΌpner

πŸ› -
Thibault Meyer

πŸ› +
Thibault Meyer

πŸ›
Thomas GΓΌttler

πŸ›
Thomas Jones-Low

πŸ›
Thomas Smith

πŸ’» πŸ›
ThrawnCA

πŸ›
Thunderforge

πŸ’» πŸ›
Tim van der Lippe

πŸ› -
Tobias Weimer

πŸ’» πŸ› +
Tobias Weimer

πŸ’» πŸ›
Tom Daly

πŸ›
Tomer Figenblat

πŸ›
Tomi De Lucca

πŸ’» πŸ›
Torsten Kleiber

πŸ›
TrackerSB

πŸ›
Ullrich Hafner

πŸ› -
Utku Cuhadaroglu

πŸ’» πŸ› +
Utku Cuhadaroglu

πŸ’» πŸ›
Valentin Brandl

πŸ›
Valeria

πŸ›
Vasily Anisimov

πŸ›
Vickenty Fesunov

πŸ›
Victor NoΓ«l

πŸ›
Vincent Galloy

πŸ’» -
Vincent HUYNH

πŸ› +
Vincent HUYNH

πŸ›
Vincent Maurin

πŸ›
Vincent Privat

πŸ›
Vishhwas

πŸ›
Vitaly

πŸ›
Vitaly Polonetsky

πŸ›
Vojtech Polivka

πŸ› -
Vsevolod Zholobov

πŸ› +
Vsevolod Zholobov

πŸ›
Vyom Yadav

πŸ’»
Wang Shidong

πŸ›
Waqas Ahmed

πŸ›
Wayne J. Earl

πŸ›
Wchenghui

πŸ›
Will Winder

πŸ› -
William Brockhus

πŸ’» πŸ› +
William Brockhus

πŸ’» πŸ›
Wilson Kurniawan

πŸ›
Wim Deblauwe

πŸ›
Woongsik Choi

πŸ›
XenoAmess

πŸ’» πŸ›
Yang

πŸ’»
YaroslavTER

πŸ› -
Young Chan

πŸ’» πŸ› +
Young Chan

πŸ’» πŸ›
YuJin Kim

πŸ›
Yuri Dolzhenko

πŸ›
Yurii Dubinka

πŸ›
Zoltan Farkas

πŸ›
Zustin

πŸ›
aaronhurst-google

πŸ› -
alexmodis

πŸ› +
alexmodis

πŸ›
andreoss

πŸ›
andrey81inmd

πŸ’» πŸ›
anicoara

πŸ›
arunprasathav

πŸ›
asiercamara

πŸ›
astillich-igniti

πŸ’» -
avesolovksyy

πŸ› +
avesolovksyy

πŸ›
avishvat

πŸ›
avivmu

πŸ›
axelbarfod1

πŸ›
b-3-n

πŸ›
balbhadra9

πŸ›
base23de

πŸ› -
bergander

πŸ› +
bergander

πŸ›
berkam

πŸ’» πŸ›
breizh31

πŸ›
caesarkim

πŸ›
carolyujing

πŸ›
cesares-basilico

πŸ›
chrite

πŸ› -
cobratbq

πŸ› +
cobratbq

πŸ›
coladict

πŸ›
cosmoJFH

πŸ›
cristalp

πŸ›
crunsk

πŸ›
cwholmes

πŸ›
cyberjj999

πŸ› -
cyw3

πŸ› +
cyw3

πŸ›
d1ss0nanz

πŸ›
danbrycefairsailcom

πŸ›
dariansanity

πŸ›
darrenmiliband

πŸ›
davidburstrom

πŸ›
dbirkman-paloalto

πŸ› -
deepak-patra

πŸ› +
deepak-patra

πŸ›
dependabot[bot]

πŸ’» πŸ›
dinesh150

πŸ›
diziaq

πŸ›
dreaminpast123

πŸ›
duanyanan

πŸ›
dutt-sanjay

πŸ› -
dylanleung

πŸ› +
dylanleung

πŸ›
dzeigler

πŸ›
ekkirala

πŸ›
emersonmoura

πŸ›
fairy

πŸ›
filiprafalowicz

πŸ’»
foxmason

πŸ› -
frankegabor

πŸ› +
frankegabor

πŸ›
frankl

πŸ›
freafrea

πŸ›
fsapatin

πŸ›
gracia19

πŸ›
guo fei

πŸ›
gurmsc5

πŸ› -
gwilymatgearset

πŸ’» πŸ› +
gwilymatgearset

πŸ’» πŸ›
haigsn

πŸ›
hemanshu070

πŸ›
henrik242

πŸ›
hongpuwu

πŸ›
hvbtup

πŸ’» πŸ›
igniti GmbH

πŸ› -
ilovezfs

πŸ› +
ilovezfs

πŸ›
itaigilo

πŸ›
jakivey32

πŸ›
jbennett2091

πŸ›
jcamerin

πŸ›
jkeener1

πŸ›
jmetertea

πŸ› -
johnra2

πŸ’» +
johnra2

πŸ’»
josemanuelrolon

πŸ’» πŸ›
kabroxiko

πŸ’» πŸ›
karwer

πŸ›
kaulonline

πŸ›
kdaemonv

πŸ›
kenji21

πŸ’» πŸ› -
kfranic

πŸ› +
kfranic

πŸ›
khalidkh

πŸ›
krzyk

πŸ›
lasselindqvist

πŸ›
lihuaib

πŸ›
lonelyma1021

πŸ›
lpeddy

πŸ› -
lujiefsi

πŸ’» +
lujiefsi

πŸ’»
lyriccoder

πŸ›
marcelmore

πŸ›
matchbox

πŸ›
matthiaskraaz

πŸ›
meandonlyme

πŸ›
mikesive

πŸ› -
milossesic

πŸ› +
milossesic

πŸ›
mriddell95

πŸ›
mrlzh

πŸ›
msloan

πŸ›
mucharlaravalika

πŸ›
mvenneman

πŸ›
nareshl119

πŸ› -
nicolas-harraudeau-sonarsource

πŸ› +
nicolas-harraudeau-sonarsource

πŸ›
noerremark

πŸ›
novsirion

πŸ›
oggboy

πŸ›
oinume

πŸ›
orimarko

πŸ’» πŸ›
pallavi agarwal

πŸ› -
parksungrin

πŸ› +
parksungrin

πŸ›
patpatpat123

πŸ›
patriksevallius

πŸ›
pbrajesh1

πŸ›
phoenix384

πŸ›
piotrszymanski-sc

πŸ’»
plan3d

πŸ› -
poojasix

πŸ› +
poojasix

πŸ›
prabhushrikant

πŸ›
pujitha8783

πŸ›
r-r-a-j

πŸ›
raghujayjunk

πŸ›
rajeshveera

πŸ›
rajeswarreddy88

πŸ› -
recdevs

πŸ› +
recdevs

πŸ›
reudismam

πŸ’» πŸ›
rijkt

πŸ›
rillig-tk

πŸ›
rmohan20

πŸ’» πŸ›
rxmicro

πŸ›
ryan-gustafson

πŸ’» πŸ› -
sabi0

πŸ› +
sabi0

πŸ›
scais

πŸ›
sebbASF

πŸ›
sergeygorbaty

πŸ’»
shilko2013

πŸ›
simeonKondr

πŸ›
snajberk

πŸ› -
sniperrifle2004

πŸ› +
sniperrifle2004

πŸ›
snuyanzin

πŸ› πŸ’»
sratz

πŸ›
stonio

πŸ›
sturton

πŸ’» πŸ›
sudharmohan

πŸ›
suruchidawar

πŸ› -
svenfinitiv

πŸ› +
svenfinitiv

πŸ›
tashiscool

πŸ›
test-git-hook

πŸ›
testation21

πŸ’» πŸ›
thanosa

πŸ›
tiandiyixian

πŸ›
tobwoerk

πŸ› -
tprouvot

πŸ› +
tprouvot

πŸ›
trentchilders

πŸ›
triandicAnt

πŸ›
trishul14

πŸ›
tsui

πŸ›
winhkey

πŸ›
witherspore

πŸ› -
wjljack

πŸ› +
wjljack

πŸ›
wuchiuwong

πŸ›
xingsong

πŸ›
xioayuge

πŸ›
xnYi9wRezm

πŸ’» πŸ›
xuanuy

πŸ›
xyf0921

πŸ› -
yalechen-cyw3

πŸ› +
yalechen-cyw3

πŸ›
yasuharu-sato

πŸ›
zenglian

πŸ›
zgrzyt93

πŸ’» πŸ›
zh3ng

πŸ›
zt_soft

πŸ›
ztt79

πŸ› -
zzzzfeng

πŸ› +
zzzzfeng

πŸ›
ÁrpÑd MagosÑnyi

πŸ›
任贡杰

πŸ› diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 37492cb23a..400d774f08 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -32,6 +32,7 @@ This is a {{ site.pmd.release_type }} release. * [#2505](https://github.com/pmd/pmd/issues/2505): \[doc] Improve side bar to show release date * java * [#3068](https://github.com/pmd/pmd/issues/3068): \[java] Some tests should not depend on real rules + * [#3603](https://github.com/pmd/pmd/issues/3603): \[java] SimplifiedTernary: no violation for 'condition ? true : false' case * [#3889](https://github.com/pmd/pmd/pull/3889): \[java] Catch LinkageError in UselessOverridingMethodRule * [#3910](https://github.com/pmd/pmd/pull/3910): \[java] UnusedPrivateField - Allow the ignored fieldnames to be configurable * java-bestpractices @@ -60,6 +61,7 @@ This is a {{ site.pmd.release_type }} release. * [#3910](https://github.com/pmd/pmd/pull/3910): \[java] UnusedPrivateField - Allow the ignored fieldnames to be configurable - [@laoseth](https://github.com/laoseth) * [#3928](https://github.com/pmd/pmd/pull/3928): \[plsql] Fix plsql parsing error in parenthesis groups - [@LiGaOg](https://github.com/LiGaOg) * [#3935](https://github.com/pmd/pmd/pull/3935): \[plsql] Fix parser exception in EXECUTE IMMEDIATE BULK COLLECT #3687 - [@Scrsloota](https://github.com/Scrsloota) +* [#3938](https://github.com/pmd/pmd/pull/3938): \[java] Modify SimplifiedTernary to meet the missing case #3603 - [@VoidxHoshi](https://github.com/VoidxHoshi) {% endtocmaker %} diff --git a/pmd-java/src/main/resources/category/java/design.xml b/pmd-java/src/main/resources/category/java/design.xml index f071a261f9..b285179dba 100644 --- a/pmd-java/src/main/resources/category/java/design.xml +++ b/pmd-java/src/main/resources/category/java/design.xml @@ -1291,12 +1291,11 @@ public void foo() throws Exception { Look for ternary operators with the form `condition ? literalBoolean : foo` or `condition ? foo : literalBoolean`. -These expressions can be simplified respectively to -`condition || foo` when the literalBoolean is true -`!condition && foo` when the literalBoolean is false -or -`!condition || foo` when the literalBoolean is true -`condition && foo` when the literalBoolean is false +These expressions can be simplified as follows: +* `condition ? true : expr` simplifies to `condition || expr` +* `condition ? false : expr` simplifies to `!condition && expr` +* `condition ? expr : true` simplifies to `!condition || expr` +* `condition ? expr : false` simplifies to `condition && expr` ]]> 3 @@ -1305,9 +1304,9 @@ or @@ -1330,6 +1329,10 @@ public class Foo { public void test4() { final boolean otherValue = condition ? something() : false; // can be as simple as condition && something(); } + + public boolean test5() { + return condition ? true : false; // can be as simple as return condition; + } } ]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SimplifiedTernary.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SimplifiedTernary.xml index 2002135780..1a01776aeb 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SimplifiedTernary.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SimplifiedTernary.xml @@ -53,12 +53,12 @@ public class Foo { - condition ? true : false - 0 + #3603 condition ? true : false + 1