From fd60aedd64594bb89c5af3a0134a44b5a713c483 Mon Sep 17 00:00:00 2001 From: mohui1999 <2381599284@qq.com> Date: Sun, 2 Apr 2023 22:13:57 +0800 Subject: [PATCH 1/4] Support AvoidAccessibilityAlteration with Lambda --- .../resources/category/java/errorprone.xml | 2 ++ .../xml/AvoidAccessibilityAlteration.xml | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index c141a2eb81..c888a021ff 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -87,6 +87,8 @@ suppression methods (e.g. by using `@SuppressWarnings` annotation). [not(ancestor::ConstructorCall[1][pmd-java:typeIs('java.security.PrivilegedAction')]/AnonymousClassDeclaration)] (: exclude inner privileged action classes :) [not(ancestor::ClassOrInterfaceDeclaration[1][pmd-java:typeIs('java.security.PrivilegedAction')])] + (: exclude privileged action lambdas :) + [not(ancestor::LambdaExpression[pmd-java:typeIs('java.security.PrivilegedAction')])] ]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml index b20329d34b..7ff2f65f94 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml @@ -184,4 +184,39 @@ public class Violation { } ]]> + + + setAccessible is ok in LambdaExpression + 0 + constructor = this.getClass().getDeclaredConstructor(String.class); + + // deliberate accessibility alteration + String privateField = AccessController.doPrivileged((PrivilegedAction)() -> { + try { + Field field = Violation.class.getDeclaredField("aPrivateField"); + field.setAccessible(true); //no violation + return (String) field.get(null); + } catch (ReflectiveOperationException | SecurityException e) { + throw new RuntimeException(e); + } + }); + } + } + + ]]> + + + + \ No newline at end of file From 3052e0fac5b863859aedd350a9e1a640fdbd7b5d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 3 Apr 2023 20:12:19 +0200 Subject: [PATCH 2/4] [java] Update rule test description (#4449) --- .../java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml index 7ff2f65f94..3e650c070c 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidAccessibilityAlteration.xml @@ -186,7 +186,7 @@ public class Violation { - setAccessible is ok in LambdaExpression + #4449 setAccessible is ok in LambdaExpression 0 \ No newline at end of file + From db84305c44ef21269c5ad3278f96faae7c806110 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 3 Apr 2023 20:12:39 +0200 Subject: [PATCH 3/4] Add @mohui1999 as a contributor --- .all-contributorsrc | 10 ++++ docs/pages/pmd/projectdocs/credits.md | 81 ++++++++++++++------------- 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 118eeb1acc..cef009b699 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -7126,6 +7126,16 @@ "bug", "code" ] + }, + { + "login": "mohui1999", + "name": "Seren", + "avatar_url": "https://avatars.githubusercontent.com/u/46819179?v=4", + "profile": "https://github.com/mohui1999", + "contributions": [ + "bug", + "code" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index 8318f60afe..08513faca1 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -655,361 +655,364 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Sebastian Schuberth

๐Ÿ›
Sebastian Schwarz

๐Ÿ› +
Seren

๐Ÿ› ๐Ÿ’ป
Sergey Gorbaty

๐Ÿ›
Sergey Kozlov

๐Ÿ›
Sergey Yanzin

๐Ÿ’ป ๐Ÿ›
Seth Wilcox

๐Ÿ’ป -
Shubham

๐Ÿ’ป ๐Ÿ› +
Shubham

๐Ÿ’ป ๐Ÿ›
Simon Abykov

๐Ÿ’ป ๐Ÿ›
Simon Xiao

๐Ÿ›
Srinivasan Venkatachalam

๐Ÿ›
Stanislav Gromov

๐Ÿ›
Stanislav Myachenkov

๐Ÿ’ป
Stefan Birkner

๐Ÿ› -
Stefan Bohn

๐Ÿ› +
Stefan Bohn

๐Ÿ›
Stefan Endrullis

๐Ÿ›
Stefan Klรถss-Schuster

๐Ÿ›
Stefan Wolf

๐Ÿ›
Stephan H. Wissel

๐Ÿ›
Stephen

๐Ÿ›
Stephen Friedrich

๐Ÿ› -
Steve Babula

๐Ÿ’ป +
Steve Babula

๐Ÿ’ป
Steven Stearns

๐Ÿ› ๐Ÿ’ป
Stexxe

๐Ÿ›
Stian Lรฅgstad

๐Ÿ›
StuartClayton5

๐Ÿ›
Supun Arunoda

๐Ÿ›
Suren Abrahamyan

๐Ÿ› -
Suvashri

๐Ÿ“– +
Suvashri

๐Ÿ“–
SwatiBGupta1110

๐Ÿ›
SyedThoufich

๐Ÿ›
Szymon Sasin

๐Ÿ›
T-chuangxin

๐Ÿ›
TERAI Atsuhiro

๐Ÿ›
TIOBE Software

๐Ÿ’ป ๐Ÿ› -
Tarush Singh

๐Ÿ’ป +
Tarush Singh

๐Ÿ’ป
Taylor Smock

๐Ÿ›
Techeira Damiรกn

๐Ÿ’ป ๐Ÿ›
Ted Husted

๐Ÿ›
TehBakker

๐Ÿ›
The Gitter Badger

๐Ÿ›
Theodoor

๐Ÿ› -
Thiago Henrique Hรผpner

๐Ÿ› +
Thiago Henrique Hรผpner

๐Ÿ›
Thibault Meyer

๐Ÿ›
Thomas Gรผttler

๐Ÿ›
Thomas Jones-Low

๐Ÿ›
Thomas Smith

๐Ÿ’ป ๐Ÿ›
ThrawnCA

๐Ÿ›
Thunderforge

๐Ÿ’ป ๐Ÿ› -
Tim van der Lippe

๐Ÿ› +
Tim van der Lippe

๐Ÿ›
Tobias Weimer

๐Ÿ’ป ๐Ÿ›
Tom Copeland

๐Ÿ› ๐Ÿ’ป ๐Ÿ“–
Tom Daly

๐Ÿ›
Tomer Figenblat

๐Ÿ›
Tomi De Lucca

๐Ÿ’ป ๐Ÿ›
Torsten Kleiber

๐Ÿ› -
TrackerSB

๐Ÿ› +
TrackerSB

๐Ÿ›
Tyson Stewart

๐Ÿ›
Ullrich Hafner

๐Ÿ›
Utku Cuhadaroglu

๐Ÿ’ป ๐Ÿ›
Valentin Brandl

๐Ÿ›
Valeria

๐Ÿ›
Valery Yatsynovich

๐Ÿ“– -
Vasily Anisimov

๐Ÿ› +
Vasily Anisimov

๐Ÿ›
Vibhor Goyal

๐Ÿ›
Vickenty Fesunov

๐Ÿ›
Victor Noรซl

๐Ÿ›
Vincent Galloy

๐Ÿ’ป
Vincent HUYNH

๐Ÿ›
Vincent Maurin

๐Ÿ› -
Vincent Privat

๐Ÿ› +
Vincent Privat

๐Ÿ›
Vishhwas

๐Ÿ›
Vitaly

๐Ÿ›
Vitaly Polonetsky

๐Ÿ›
Vojtech Polivka

๐Ÿ›
Vsevolod Zholobov

๐Ÿ›
Vyom Yadav

๐Ÿ’ป -
Wang Shidong

๐Ÿ› +
Wang Shidong

๐Ÿ›
Waqas Ahmed

๐Ÿ›
Wayne J. Earl

๐Ÿ›
Wchenghui

๐Ÿ›
Will Winder

๐Ÿ›
William Brockhus

๐Ÿ’ป ๐Ÿ›
Wilson Kurniawan

๐Ÿ› -
Wim Deblauwe

๐Ÿ› +
Wim Deblauwe

๐Ÿ›
Woongsik Choi

๐Ÿ›
XenoAmess

๐Ÿ’ป ๐Ÿ›
Yang

๐Ÿ’ป
YaroslavTER

๐Ÿ›
Yasar Shaikh

๐Ÿ’ป
Young Chan

๐Ÿ’ป ๐Ÿ› -
YuJin Kim

๐Ÿ› +
YuJin Kim

๐Ÿ›
Yuri Dolzhenko

๐Ÿ›
Yurii Dubinka

๐Ÿ›
Zoltan Farkas

๐Ÿ›
Zustin

๐Ÿ›
aaronhurst-google

๐Ÿ› ๐Ÿ’ป
alexmodis

๐Ÿ› -
andreoss

๐Ÿ› +
andreoss

๐Ÿ›
andrey81inmd

๐Ÿ’ป ๐Ÿ›
anicoara

๐Ÿ›
arunprasathav

๐Ÿ›
asiercamara

๐Ÿ›
astillich-igniti

๐Ÿ’ป
avesolovksyy

๐Ÿ› -
avishvat

๐Ÿ› +
avishvat

๐Ÿ›
avivmu

๐Ÿ›
axelbarfod1

๐Ÿ›
b-3-n

๐Ÿ›
balbhadra9

๐Ÿ›
base23de

๐Ÿ›
bergander

๐Ÿ› -
berkam

๐Ÿ’ป ๐Ÿ› +
berkam

๐Ÿ’ป ๐Ÿ›
breizh31

๐Ÿ›
caesarkim

๐Ÿ›
carolyujing

๐Ÿ›
cbfiddle

๐Ÿ›
cesares-basilico

๐Ÿ›
chrite

๐Ÿ› -
cobratbq

๐Ÿ› +
cobratbq

๐Ÿ›
coladict

๐Ÿ›
cosmoJFH

๐Ÿ›
cristalp

๐Ÿ›
crunsk

๐Ÿ›
cwholmes

๐Ÿ›
cyberjj999

๐Ÿ› -
cyw3

๐Ÿ› +
cyw3

๐Ÿ›
d1ss0nanz

๐Ÿ›
dague1

๐Ÿ“–
dalizi007

๐Ÿ’ป
danbrycefairsailcom

๐Ÿ›
dariansanity

๐Ÿ›
darrenmiliband

๐Ÿ› -
davidburstrom

๐Ÿ› +
davidburstrom

๐Ÿ›
dbirkman-paloalto

๐Ÿ›
deepak-patra

๐Ÿ›
dependabot[bot]

๐Ÿ’ป ๐Ÿ›
dinesh150

๐Ÿ›
diziaq

๐Ÿ›
dreaminpast123

๐Ÿ› -
duanyanan

๐Ÿ› +
duanyanan

๐Ÿ›
dutt-sanjay

๐Ÿ›
dylanleung

๐Ÿ›
dzeigler

๐Ÿ›
ekkirala

๐Ÿ›
emersonmoura

๐Ÿ›
fairy

๐Ÿ› -
filiprafalowicz

๐Ÿ’ป +
filiprafalowicz

๐Ÿ’ป
foxmason

๐Ÿ›
frankegabor

๐Ÿ›
frankl

๐Ÿ›
freafrea

๐Ÿ›
fsapatin

๐Ÿ›
gracia19

๐Ÿ› -
guo fei

๐Ÿ› +
guo fei

๐Ÿ›
gurmsc5

๐Ÿ›
gwilymatgearset

๐Ÿ’ป ๐Ÿ›
haigsn

๐Ÿ›
hemanshu070

๐Ÿ›
henrik242

๐Ÿ›
hongpuwu

๐Ÿ› -
hvbtup

๐Ÿ’ป ๐Ÿ› +
hvbtup

๐Ÿ’ป ๐Ÿ›
igniti GmbH

๐Ÿ›
ilovezfs

๐Ÿ›
itaigilo

๐Ÿ›
jakivey32

๐Ÿ›
jbennett2091

๐Ÿ›
jcamerin

๐Ÿ› -
jkeener1

๐Ÿ› +
jkeener1

๐Ÿ›
jmetertea

๐Ÿ›
johnra2

๐Ÿ’ป
josemanuelrolon

๐Ÿ’ป ๐Ÿ›
kabroxiko

๐Ÿ’ป ๐Ÿ›
karwer

๐Ÿ›
kaulonline

๐Ÿ› -
kdaemonv

๐Ÿ› +
kdaemonv

๐Ÿ›
kdebski85

๐Ÿ› ๐Ÿ’ป
kenji21

๐Ÿ’ป ๐Ÿ›
kfranic

๐Ÿ›
khalidkh

๐Ÿ›
koalalam

๐Ÿ›
krzyk

๐Ÿ› -
lasselindqvist

๐Ÿ› +
lasselindqvist

๐Ÿ›
lgemeinhardt

๐Ÿ›
lihuaib

๐Ÿ›
lonelyma1021

๐Ÿ›
lpeddy

๐Ÿ›
lujiefsi

๐Ÿ’ป
lukelukes

๐Ÿ’ป -
lyriccoder

๐Ÿ› +
lyriccoder

๐Ÿ›
marcelmore

๐Ÿ›
matchbox

๐Ÿ›
matthiaskraaz

๐Ÿ›
meandonlyme

๐Ÿ›
mikesive

๐Ÿ›
milossesic

๐Ÿ› -
mluckam

๐Ÿ’ป +
mluckam

๐Ÿ’ป
mohan-chinnappan-n

๐Ÿ’ป
mriddell95

๐Ÿ›
mrlzh

๐Ÿ›
msloan

๐Ÿ›
mucharlaravalika

๐Ÿ›
mvenneman

๐Ÿ› -
nareshl119

๐Ÿ› +
nareshl119

๐Ÿ›
nicolas-harraudeau-sonarsource

๐Ÿ›
noerremark

๐Ÿ›
novsirion

๐Ÿ›
oggboy

๐Ÿ›
oinume

๐Ÿ›
orimarko

๐Ÿ’ป ๐Ÿ› -
pacvz

๐Ÿ’ป +
pacvz

๐Ÿ’ป
pallavi agarwal

๐Ÿ›
parksungrin

๐Ÿ›
patpatpat123

๐Ÿ›
patriksevallius

๐Ÿ›
pbrajesh1

๐Ÿ›
phoenix384

๐Ÿ› -
piotrszymanski-sc

๐Ÿ’ป +
piotrszymanski-sc

๐Ÿ’ป
plan3d

๐Ÿ›
poojasix

๐Ÿ›
prabhushrikant

๐Ÿ›
pujitha8783

๐Ÿ›
r-r-a-j

๐Ÿ›
raghujayjunk

๐Ÿ› -
rajeshveera

๐Ÿ› +
rajeshveera

๐Ÿ›
rajeswarreddy88

๐Ÿ›
recdevs

๐Ÿ›
reudismam

๐Ÿ’ป ๐Ÿ›
rijkt

๐Ÿ›
rillig-tk

๐Ÿ›
rmohan20

๐Ÿ’ป ๐Ÿ› -
rnveach

๐Ÿ› +
rnveach

๐Ÿ›
rxmicro

๐Ÿ›
ryan-gustafson

๐Ÿ’ป ๐Ÿ›
sabi0

๐Ÿ›
scais

๐Ÿ›
sebbASF

๐Ÿ›
sergeygorbaty

๐Ÿ’ป -
shilko2013

๐Ÿ› +
shilko2013

๐Ÿ›
shiomiyan

๐Ÿ“–
simeonKondr

๐Ÿ›
snajberk

๐Ÿ›
sniperrifle2004

๐Ÿ›
snuyanzin

๐Ÿ› ๐Ÿ’ป
sratz

๐Ÿ› -
stonio

๐Ÿ› +
stonio

๐Ÿ›
sturton

๐Ÿ’ป ๐Ÿ›
sudharmohan

๐Ÿ›
suruchidawar

๐Ÿ›
svenfinitiv

๐Ÿ›
tashiscool

๐Ÿ›
test-git-hook

๐Ÿ› -
testation21

๐Ÿ’ป ๐Ÿ› +
testation21

๐Ÿ’ป ๐Ÿ›
thanosa

๐Ÿ›
tiandiyixian

๐Ÿ›
tobwoerk

๐Ÿ›
tprouvot

๐Ÿ› ๐Ÿ’ป
trentchilders

๐Ÿ›
triandicAnt

๐Ÿ› -
trishul14

๐Ÿ› +
trishul14

๐Ÿ›
tsui

๐Ÿ›
winhkey

๐Ÿ›
witherspore

๐Ÿ›
wjljack

๐Ÿ›
wuchiuwong

๐Ÿ›
xingsong

๐Ÿ› -
xioayuge

๐Ÿ› +
xioayuge

๐Ÿ›
xnYi9wRezm

๐Ÿ’ป ๐Ÿ›
xuanuy

๐Ÿ›
xyf0921

๐Ÿ›
yalechen-cyw3

๐Ÿ›
yasuharu-sato

๐Ÿ›
zenglian

๐Ÿ› -
zgrzyt93

๐Ÿ’ป ๐Ÿ› +
zgrzyt93

๐Ÿ’ป ๐Ÿ›
zh3ng

๐Ÿ›
zt_soft

๐Ÿ›
ztt79

๐Ÿ›
zzzzfeng

๐Ÿ›
รrpรกd Magosรกnyi

๐Ÿ›
ไปป่ดตๆฐ

๐Ÿ› + +
่Œ…ๅปถๅฎ‰

๐Ÿ’ป From c71b3f5f3ad95d2c6a9b8853f414e9ee1d3ac703 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 3 Apr 2023 20:15:13 +0200 Subject: [PATCH 4/4] [doc] Update release notes (#4450, #4449) --- docs/pages/release_notes.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 14d4904e35..e3fb66813f 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -39,6 +39,10 @@ for all.

This section lists the most important changes from the last release candidate. The remaining section describe the complete release notes for 7.0.0. +Fixed issues: +* java-errorprone + * [#4449](https://github.com/pmd/pmd/issues/4449): \[java] AvoidAccessibilityAlteration: Possible false positive in AvoidAccessibilityAlteration rule when using Lambda expression + ### ๐Ÿš€ Major Features and Enhancements #### New official logo @@ -359,6 +363,7 @@ Language specific fixes: * [#3351](https://github.com/pmd/pmd/issues/3351): \[java] ConstructorCallsOverridableMethod ignores abstract methods * [#3400](https://github.com/pmd/pmd/issues/3400): \[java] AvoidUsingOctalValues FN with underscores * [#4356](https://github.com/pmd/pmd/pull/4356): \[java] Fix NPE in CloseResourceRule + * [#4449](https://github.com/pmd/pmd/issues/4449): \[java] AvoidAccessibilityAlteration: Possible false positive in AvoidAccessibilityAlteration rule when using Lambda expression * java-multithreading * [#2537](https://github.com/pmd/pmd/issues/2537): \[java] DontCallThreadRun can't detect the case that call run() in `this.run()` * [#2538](https://github.com/pmd/pmd/issues/2538): \[java] DontCallThreadRun can't detect the case that call run() in `foo.bar.run()` @@ -389,6 +394,7 @@ Language specific fixes: * [#3866](https://github.com/pmd/pmd/pull/3866): \[core] Add CLI Progress Bar - [@JerritEic](https://github.com/JerritEic) (@JerritEic) * [#4412](https://github.com/pmd/pmd/pull/4412): \[doc] Added new error msg to ConstantsInInterface - [David Ljunggren](https://github.com/dague1) (@dague1) * [#4428](https://github.com/pmd/pmd/pull/4428): \[apex] ApexBadCrypto bug fix for #4427 - inline detection of hard coded values - [Steven Stearns](https://github.com/sfdcsteve) (@sfdcsteve) +* [#4450](https://github.com/pmd/pmd/pull/4450): \[java] Fix #4449 AvoidAccessibilityAlteration: Correctly handle Lambda expressions in PrivilegedAction scenarios - [Seren](https://github.com/mohui1999) (@mohui1999) ### ๐Ÿ“ˆ Stats * 4416 commits