Skip to content

Commit bc63791

Browse files
Artem LabazinArtem Labazin
authored andcommitted
Small refactoring
1 parent f834b52 commit bc63791

File tree

8 files changed

+110
-194
lines changed

8 files changed

+110
-194
lines changed

.codestyle/checkstyle.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ limitations under the License.
5252
</module>
5353

5454

55-
<!--http://checkstyle.sourceforge.net/config_sizes.html#FileLength-->
56-
<module name="FileLength">
57-
<property name="max" value="300"/>
58-
</module>
59-
60-
6155
<!--http://checkstyle.sourceforge.net/config_whitespace.html#FileTabCharacter-->
6256
<module name="FileTabCharacter">
6357
<property name="eachLine" value="true"/>
@@ -194,7 +188,7 @@ limitations under the License.
194188
</module>
195189
<module name="MethodLength">
196190
<property name="tokens" value="METHOD_DEF"/>
197-
<property name="max" value="30"/>
191+
<property name="max" value="60"/>
198192
<property name="countEmpty" value="false"/>
199193
</module>
200194
<module name="ParameterNumber">
@@ -321,9 +315,6 @@ limitations under the License.
321315
<!-- Checks for common coding problems -->
322316
<!-- See http://checkstyle.sf.net/config_coding.html -->
323317
<module name="CovariantEquals"/>
324-
<!-- <module name="DeclarationOrder">
325-
<property name="ignoreConstructors" value="true"/>
326-
</module> -->
327318
<module name="DefaultComesLast"/>
328319
<module name="EmptyStatement"/>
329320
<module name="EqualsAvoidNull"/>
@@ -362,7 +353,6 @@ limitations under the License.
362353
<module name="SuperClone"/>
363354
<module name="SuperFinalize"/>
364355
<module name="UnnecessaryParentheses"/>
365-
<module name="VariableDeclarationUsageDistance"/>
366356

367357

368358
<!-- Checks for class design -->
@@ -372,7 +362,6 @@ limitations under the License.
372362
</module>
373363
<module name="FinalClass"/>
374364
<module name="HideUtilityClassConstructor"/>
375-
<module name="MutableException"/>
376365
<module name="OneTopLevelClass"/>
377366

378367
<!-- Miscellaneous other checks. -->

.codestyle/findbugs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ limitations under the License.
2323
<Match>
2424
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"/>
2525
</Match>
26+
<Match>
27+
<Bug pattern="BC_UNCONFIRMED_CAST"/>
28+
</Match>
2629
</FindBugsFilter>

.codestyle/pmd.xml

Lines changed: 38 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -23,144 +23,55 @@ limitations under the License.
2323

2424
<description>PMD Rules</description>
2525

26-
<rule ref="rulesets/java/basic.xml">
27-
<exclude name="AvoidUsingHardCodedIP" />
26+
<rule ref="category/java/bestpractices.xml">
2827
</rule>
29-
30-
<rule ref="rulesets/java/braces.xml" />
31-
<rule ref="rulesets/java/clone.xml" />
32-
<rule ref="rulesets/java/unusedcode.xml"/>
33-
<rule ref="rulesets/java/finalizers.xml" />
34-
35-
36-
<rule ref="rulesets/java/imports.xml">
37-
<!-- Stupid rule... -->
28+
<rule ref="category/java/codestyle.xml">
29+
<exclude name="AbstractNaming" />
30+
<exclude name="AtLeastOneConstructor" />
31+
<exclude name="AvoidPrefixingMethodParameters" />
32+
<exclude name="CommentDefaultAccessModifier" />
33+
<exclude name="DefaultPackage" />
34+
<exclude name="FieldDeclarationsShouldBeAtStartOfClass" />
35+
<exclude name="LocalVariableCouldBeFinal" />
36+
<exclude name="LongVariable" />
37+
<exclude name="MethodArgumentCouldBeFinal" />
38+
<exclude name="OnlyOneReturn" />
39+
<exclude name="ShortClassName" />
40+
<exclude name="ShortMethodName" />
41+
<exclude name="ShortVariable" />
3842
<exclude name="TooManyStaticImports" />
43+
<exclude name="UselessParentheses" />
3944
</rule>
40-
41-
<rule ref="rulesets/java/codesize.xml" >
42-
<!-- See the explanation for TooManyMethods.-->
45+
<rule ref="category/java/design.xml">
46+
<exclude name="AvoidCatchingGenericException" />
47+
<exclude name="AvoidRethrowingException" />
48+
<exclude name="AvoidThrowingNullPointerException" />
49+
<exclude name="ExcessiveImports" />
50+
<exclude name="ExcessivePublicCount" />
51+
<exclude name="LawOfDemeter" />
52+
<exclude name="LoosePackageCoupling" />
4353
<exclude name="TooManyFields" />
44-
<!-- Design is very hard to measure by numbers like this.-->
45-
<!-- The number and quality of dependencies might be a better indicator, -->
46-
<!-- and that requires a different tool.-->
4754
<exclude name="TooManyMethods" />
48-
<!-- See the explanation for TooManyMethods.-->
49-
<exclude name="ExcessivePublicCount" />
50-
<!-- Needs better understanding and proper configuration-->
51-
<exclude name="StdCyclomaticComplexity" />
52-
<!-- Needs better understanding and proper configuration-->
53-
<exclude name="ModifiedCyclomaticComplexity" />
54-
<!-- See the explanation for TooManyMethods.-->
55-
<exclude name="ExcessiveParameterList" />
56-
<!-- Too abstract rule -->
57-
<exclude name="CyclomaticComplexity" />
58-
</rule>
5955

60-
<rule ref="rulesets/java/design.xml">
61-
<!-- Sometimes important to avoid "DOS attack" but not as a general rule-->
62-
<exclude name="AvoidSynchronizedAtMethodLevel" />
63-
<!-- It's just extra effort to write and read the final keyword-->
64-
<exclude name="ClassWithOnlyPrivateConstructorsShouldBeFinal" />
65-
<!-- Maybe good idea if PMD could exclude null checks from this-->
66-
<exclude name="ConfusingTernary" />
67-
<!-- Statistical analysis is prone to givin false positives. Potential god classes-->
68-
<!-- most probably violate something else, too.-->
69-
<!-- And dependency analysis tools also help here.-->
70-
<exclude name="GodClass" />
71-
<!-- Switch is sometimes very readable-->
72-
<exclude name="TooFewBranchesForASwitchStatement"/>
73-
<!-- A static utility is a static utility even if it masquerades as something-->
74-
<!-- else by using the Singleton pattern-->
75-
<exclude name="UseUtilityClass" />
76-
<!-- This is good advice, but since it's violated so much in this project-->
77-
<!-- and the problem is not big (especially with good syntax colouring),-->
78-
<!-- we'll keep this ignored for now.-->
79-
<exclude name="AvoidReassigningParameters" />
80-
<!-- Good idea almost always, but not quite.-->
81-
<!--<exclude name="ReturnEmptyArrayRatherThanNull" />-->
82-
<!-- Sometimes one step at a time makes clearer code.-->
83-
<!-- Debugging is also easier if the return value is in a variable.-->
84-
<exclude name="UnnecessaryLocalBeforeReturn" />
85-
<!-- There are valid reasons for passing arrays (making it nullable for example)-->
86-
<exclude name="UseVarargs" />
87-
<!-- TODO explain what false positives this gives-->
88-
<exclude name="MissingBreakInSwitch" />
89-
<!-- TODO enable when all findings have been fixed-->
90-
<exclude name="UseLocaleWithCaseConversions" />
91-
<!-- It gives a lot of warnings on 'equals' method, fixing would decrease readability-->
92-
<exclude name="SimplifyBooleanReturns"/>
93-
<!--Gives false positive-->
94-
<exclude name="FieldDeclarationsShouldBeAtStartOfClass"/>
95-
<!-- Good rule but in practice to often suppressed -->
96-
<exclude name="PreserveStackTrace"/>
97-
98-
<exclude name="AccessorMethodGeneration"/>
56+
<!-- remove it -->
57+
<exclude name="NcssCount" />
9958
</rule>
59+
<rule ref="category/java/documentation.xml">
60+
<exclude name="CommentSize" />
10061

101-
<rule ref="rulesets/java/migrating.xml">
102-
<!-- The annotation is not as readable and there is no way to state which-->
103-
<!-- line should throw the exception and with what message-->
104-
<exclude name="JUnitUseExpected" />
105-
<!-- Main code is not junit code-->
106-
<exclude name="JUnit4TestShouldUseTestAnnotation" />
62+
<!-- remove it -->
63+
<exclude name="CommentRequired" />
10764
</rule>
108-
109-
<rule ref="rulesets/java/naming.xml">
110-
<!-- Often good to start name with Abstract, but on the other hand this-->
111-
<!-- rule is a bit too much like Hungarian notation and I in interface names.-->
112-
<!-- Who cares if it's abstract or not when you are using it?-->
113-
<exclude name="AbstractNaming" />
114-
<!-- Opinion, for me a getter is not a command, it's a declarative-->
115-
<!-- data reference-->
65+
<rule ref="category/java/errorprone.xml">
66+
<exclude name="AvoidFieldNameMatchingTypeName" />
11667
<exclude name="AvoidFieldNameMatchingMethodName" />
117-
<!-- Why should generics not be named properly, like all other things-->
118-
<!-- (well, except Windows filesystem roots)?-->
119-
<exclude name="GenericsNaming" />
120-
<!-- It can be long if it's the only way to make it good-->
121-
<exclude name="LongVariable" />
122-
<!-- It can be short if it's good-->
123-
<exclude name="ShortVariable" />
124-
<!-- TODO explain why.-->
125-
<exclude name="BooleanGetMethodName" />
126-
<!-- It can be short if it's good-->
127-
<exclude name="ShortClassName" />
128-
<!-- It can be short if it's good-->
129-
<exclude name="ShortMethodName" />
130-
</rule>
131-
132-
<rule ref="rulesets/java/optimizations.xml">
133-
<!-- Too many false hits. Optimization can't be done with static analysis.
134-
Besides, following this may encourage the antipattern of using too broad
135-
scope for stuff: -->
136-
<exclude name="AvoidInstantiatingObjectsInLoops" />
137-
<!-- Good principle but too verbose in practice: -->
138-
<exclude name="MethodArgumentCouldBeFinal" />
139-
<!-- Good principle and maybe sometimes even practical but not in this
140-
project: -->
141-
<exclude name="LocalVariableCouldBeFinal" />
142-
<exclude name="RedundantFieldInitializer" />
68+
<exclude name="BeanMembersShouldSerialize" />
69+
<exclude name="DataflowAnomalyAnalysis" />
70+
<exclude name="MissingBreakInSwitch" />
14371
</rule>
144-
145-
<rule ref="rulesets/java/strictexception.xml" >
146-
<!-- NPE communicates very cleary what is happening, it is not-->
147-
<!-- interesting who reports it (jvm or user code)-->
148-
<exclude name="AvoidThrowingNullPointerException" />
149-
<!-- TODO explain why-->
150-
<exclude name="AvoidCatchingGenericException" />
151-
<!-- TODO explain why-->
152-
<exclude name="AvoidThrowingRawExceptionTypes" />
153-
<!-- One valid case is to catch runtime, throw as such and after that-->
154-
<!-- catch Exception and wrap as runtime.-->
155-
<!-- Without the first all runtimes are unnecessarily wrapped.-->
156-
<exclude name="AvoidRethrowingException" />
157-
<!-- There are case which should throws generic exceptions -->
158-
<exclude name="SignatureDeclareThrowsException" />
72+
<rule ref="category/java/multithreading.xml">
15973
</rule>
160-
161-
<rule ref="rulesets/java/strings.xml" >
162-
<!-- Splitting to multiple lines is sometimes more readable.-->
163-
<!-- Besides, where's the proof that it affects performance?-->
164-
<exclude name="ConsecutiveAppendsShouldReuse" />
74+
<rule ref="category/java/performance.xml">
75+
<exclude name="AvoidUsingShortType" />
16576
</rule>
16677
</ruleset>

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Add more tests.
1313
- Add `JavaDoc`.
1414

15+
## [1.3.3](https://github.com/appulse-projects/utils-java/releases/tag/1.3.3) - 2018-03-15
16+
17+
Small refactoring.
18+
19+
### Changed
20+
21+
- Updated dependencies.
22+
- Corrected codestyle files.
23+
1524
## [1.3.2](https://github.com/appulse-projects/utils-java/releases/tag/1.3.2) - 2018-02-14
1625

1726
Minor release with simple bug fix.

pom.xml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ limitations under the License.
2424

2525
<groupId>io.appulse</groupId>
2626
<artifactId>utils-java</artifactId>
27-
<version>1.3.2</version>
27+
<version>1.3.3</version>
2828
<packaging>jar</packaging>
2929

3030
<properties>
@@ -62,7 +62,7 @@ limitations under the License.
6262
<url>https://github.com/appulse-projects/utils-java</url>
6363
<connection>scm:git:https://github.com/appulse-projects/utils-java.git</connection>
6464
<developerConnection>scm:git:https://github.com/appulse-projects/utils-java.git</developerConnection>
65-
<tag>1.3.2</tag>
65+
<tag>1.3.3</tag>
6666
</scm>
6767

6868
<distributionManagement>
@@ -105,7 +105,7 @@ limitations under the License.
105105
<dependency>
106106
<groupId>com.google.code.findbugs</groupId>
107107
<artifactId>annotations</artifactId>
108-
<version>3.0.1u2</version>
108+
<version>3.0.1</version>
109109
<scope>provided</scope>
110110
</dependency>
111111
<dependency>
@@ -124,7 +124,7 @@ limitations under the License.
124124
<dependency>
125125
<groupId>org.assertj</groupId>
126126
<artifactId>assertj-core</artifactId>
127-
<version>3.9.0</version>
127+
<version>3.9.1</version>
128128
<scope>test</scope>
129129
</dependency>
130130
</dependencies>
@@ -148,9 +148,10 @@ limitations under the License.
148148
<plugin>
149149
<groupId>org.apache.maven.plugins</groupId>
150150
<artifactId>maven-javadoc-plugin</artifactId>
151-
<version>2.10.4</version>
151+
<version>3.0.0</version>
152152
<configuration>
153153
<additionalOptions>-Xdoclint:none</additionalOptions>
154+
<additionalparam>-Xdoclint:none</additionalparam>
154155
<breakiterator>true</breakiterator>
155156
<charset>UTF-8</charset>
156157
<docencoding>UTF-8</docencoding>
@@ -174,7 +175,7 @@ limitations under the License.
174175
<plugin>
175176
<groupId>org.apache.maven.plugins</groupId>
176177
<artifactId>maven-surefire-plugin</artifactId>
177-
<version>2.20.1</version>
178+
<version>2.21.0</version>
178179
<configuration>
179180
<trimStackTrace>false</trimStackTrace>
180181
<includes>
@@ -189,7 +190,7 @@ limitations under the License.
189190
<plugin>
190191
<groupId>org.apache.maven.plugins</groupId>
191192
<artifactId>maven-failsafe-plugin</artifactId>
192-
<version>2.20.1</version>
193+
<version>2.21.0</version>
193194
<configuration>
194195
<includes>
195196
<include>**/*IntegrationTest.java</include>
@@ -232,11 +233,14 @@ limitations under the License.
232233
<plugin>
233234
<groupId>org.apache.maven.plugins</groupId>
234235
<artifactId>maven-pmd-plugin</artifactId>
235-
<version>3.8</version>
236+
<version>3.9.0</version>
236237
<configuration>
237238
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
238239
<targetJdk>${maven.compiler.source}</targetJdk>
239240
<verbose>true</verbose>
241+
<failOnViolation>true</failOnViolation>
242+
<printFailingErrors>true</printFailingErrors>
243+
<analysisCache>true</analysisCache>
240244
<linkXRef>false</linkXRef>
241245
<rulesets>
242246
<ruleset>${project.basedir}/.codestyle/pmd.xml</ruleset>
@@ -277,7 +281,7 @@ limitations under the License.
277281
<failOnViolation>true</failOnViolation>
278282
<linkXRef>false</linkXRef>
279283
<propertyExpansion>codestyleFolder=${project.basedir}/.codestyle</propertyExpansion>
280-
<includeTestSourceDirectory>false</includeTestSourceDirectory>
284+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
281285
</configuration>
282286
</execution>
283287
</executions>

src/main/java/io/appulse/utils/SocketUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static Optional<Integer> findFreePort () {
4040
}
4141

4242
public static Optional<Integer> findFreePort (int from, int to) {
43-
for (int port = from; port <= to; port++) {
43+
for (int port = to; port >= from; port--) {
4444
if (isPortAvailable(port)) {
4545
return of(port);
4646
}

src/test/java/io/appulse/utils/BytesUtilsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616

1717
package io.appulse.utils;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
2019
import static lombok.AccessLevel.PRIVATE;
20+
import static org.assertj.core.api.Assertions.assertThat;
2121

2222
import java.io.IOException;
23-
import java.nio.ByteBuffer;
2423
import java.io.InputStream;
24+
import java.nio.ByteBuffer;
2525
import java.util.Arrays;
2626

27-
import org.junit.Test;
2827
import lombok.experimental.FieldDefaults;
2928
import lombok.val;
29+
import org.junit.Test;
3030

3131
public class BytesUtilsTest {
3232

0 commit comments

Comments
 (0)