File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1529,6 +1529,30 @@ If a usage of `ThreadLocal` doesn't fall into either of these categories, it can
1529
1529
There is an inspection "ThreadLocal field not declared static final" in IntelliJ IDEA which
1530
1530
corresponds to this item.
1531
1531
1532
+ Static ` ThreadLocal ` fields could also be enforced using Checkstyle, using the following combination
1533
+ of checks:
1534
+ ``` xml
1535
+ <!-- Enforce 'private static final' order of modifiers -->
1536
+ <module name =" ModifierOrder" />
1537
+
1538
+ <!-- Ensure all ThreadLocal fields are private -->
1539
+ <!-- Requires https://github.com/sevntu-checkstyle/sevntu.checkstyle -->
1540
+ <module name =" AvoidModifiersForTypesCheck" >
1541
+ <property name =" forbiddenClassesRegexpProtected" value =" ThreadLocal" />
1542
+ <property name =" forbiddenClassesRegexpPublic" value =" ThreadLocal" />
1543
+ <property name =" forbiddenClassesRegexpPackagePrivate" value =" ThreadLocal" />
1544
+ </module >
1545
+
1546
+ <!-- Prohibit any ThreadLocal field which is not private static final -->
1547
+ <module name =" Regexp" >
1548
+ <property name =" id" value =" nonStaticThreadLocal" />
1549
+ <property name =" format"
1550
+ value =" ^\s*private\s+(ThreadLocal|static\s+ThreadLocal|final\s+ThreadLocal)" />
1551
+ <property name =" illegalPattern" value =" true" />
1552
+ <property name =" message" value =" Non-static final ThreadLocal" />
1553
+ </module >
1554
+ ```
1555
+
1532
1556
<a name =" threadlocal-design " ></a >
1533
1557
[ #] ( #threadlocal-design ) TL.2. Doesn't a ** ` ThreadLocal ` mask issues with the code, such as poor
1534
1558
control flow or data flow design?** Is it possible to redesign the system without using
You can’t perform that action at this time.
0 commit comments