Use autogenerated versions of docs

This commit is contained in:
Juan Martín Sotuyo Dodero
2017-12-08 00:39:29 -03:00
parent ac36d678bb
commit 53a9449141
2 changed files with 22 additions and 34 deletions

View File

@ -294,6 +294,7 @@ folder: pmd/rules
* [AddEmptyString](pmd_rules_java_performance.html#addemptystring): The conversion of literals to strings by concatenating them with empty strings is inefficient.It ... * [AddEmptyString](pmd_rules_java_performance.html#addemptystring): The conversion of literals to strings by concatenating them with empty strings is inefficient.It ...
* [AppendCharacterWithChar](pmd_rules_java_performance.html#appendcharacterwithchar): Avoid concatenating characters as strings in StringBuffer/StringBuilder.append methods. * [AppendCharacterWithChar](pmd_rules_java_performance.html#appendcharacterwithchar): Avoid concatenating characters as strings in StringBuffer/StringBuilder.append methods.
* [AvoidArrayLoops](pmd_rules_java_performance.html#avoidarrayloops): Instead of manually copying data between two arrays, use the efficient System.arraycopy method in... * [AvoidArrayLoops](pmd_rules_java_performance.html#avoidarrayloops): Instead of manually copying data between two arrays, use the efficient System.arraycopy method in...
* [AvoidFileStream](pmd_rules_java_performance.html#avoidfilestream): Use Files.newInputStream(Paths.get(fileName)) instead of new FileInputStream(fileName).Use Files....
* [AvoidInstantiatingObjectsInLoops](pmd_rules_java_performance.html#avoidinstantiatingobjectsinloops): New objects created within loops should be checked to see if they can created outside them and re... * [AvoidInstantiatingObjectsInLoops](pmd_rules_java_performance.html#avoidinstantiatingobjectsinloops): New objects created within loops should be checked to see if they can created outside them and re...
* [AvoidUsingShortType](pmd_rules_java_performance.html#avoidusingshorttype): Java uses the 'short' type to reduce memory usage, not to optimize calculation. In fact, the JVM ... * [AvoidUsingShortType](pmd_rules_java_performance.html#avoidusingshorttype): Java uses the 'short' type to reduce memory usage, not to optimize calculation. In fact, the JVM ...
* [BigIntegerInstantiation](pmd_rules_java_performance.html#bigintegerinstantiation): Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) andfor Ja... * [BigIntegerInstantiation](pmd_rules_java_performance.html#bigintegerinstantiation): Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) andfor Ja...

View File

@ -5,7 +5,7 @@ permalink: pmd_rules_java_performance.html
folder: pmd/rules/java folder: pmd/rules/java
sidebaractiveurl: /pmd_rules_java.html sidebaractiveurl: /pmd_rules_java.html
editmepath: ../pmd-java/src/main/resources/category/java/performance.xml editmepath: ../pmd-java/src/main/resources/category/java/performance.xml
keywords: Performance, AddEmptyString, AppendCharacterWithChar, AvoidArrayLoops, AvoidInstantiatingObjectsInLoops, AvoidUsingShortType, BigIntegerInstantiation, BooleanInstantiation, ByteInstantiation, ConsecutiveAppendsShouldReuse, ConsecutiveLiteralAppends, InefficientEmptyStringCheck, InefficientStringBuffering, InsufficientStringBufferDeclaration, IntegerInstantiation, LongInstantiation, OptimizableToArrayCall, RedundantFieldInitializer, SimplifyStartsWith, ShortInstantiation, StringInstantiation, StringToString, TooFewBranchesForASwitchStatement, UnnecessaryWrapperObjectCreation, UseArrayListInsteadOfVector, UseArraysAsList, UseIndexOfChar, UselessStringValueOf, UseStringBufferForStringAppends, UseStringBufferLength keywords: Performance, AddEmptyString, AppendCharacterWithChar, AvoidArrayLoops, AvoidFileStream, AvoidInstantiatingObjectsInLoops, AvoidUsingShortType, BigIntegerInstantiation, BooleanInstantiation, ByteInstantiation, ConsecutiveAppendsShouldReuse, ConsecutiveLiteralAppends, InefficientEmptyStringCheck, InefficientStringBuffering, InsufficientStringBufferDeclaration, IntegerInstantiation, LongInstantiation, OptimizableToArrayCall, RedundantFieldInitializer, SimplifyStartsWith, ShortInstantiation, StringInstantiation, StringToString, TooFewBranchesForASwitchStatement, UnnecessaryWrapperObjectCreation, UseArrayListInsteadOfVector, UseArraysAsList, UseIndexOfChar, UselessStringValueOf, UseStringBufferForStringAppends, UseStringBufferLength
--- ---
## AddEmptyString ## AddEmptyString
@ -115,17 +115,13 @@ public class Test {
**Priority:** High (1) **Priority:** High (1)
Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter. **Minimum Language Version:** Java 1.7
- Use Files.newInputStream(Paths.get(fileName)) in place of new FileInputStream(fileName).
- Use Files.newOutputStream(Paths.get(fileName)) instead of new FileOutputStream(fileName).
- Use Files.newBufferedReader(Paths.get(fileName)) instead of new FileReader(fileName).
- Use Files.newBufferedWriter(Paths.get(fileName)) instead of new FileWriter(fileName).
The FileInputStream and FileOutputStream classes contains a finalizer method which will cause garbage collection pauses. Use Files.newInputStream(Paths.get(fileName)) instead of new FileInputStream(fileName).
See [JDK-8080225](https://bugs.openjdk.java.net/browse/JDK-8080225) for details. Use Files.newOutputStream(Paths.get(fileName)) instead of new FileOutputStream(fileName).
Use Files.newBufferedReader(Paths.get(fileName)) instead of new FileReader(fileName).
Use Files.newBufferedWriter(Paths.get(fileName)) instead of new FileWriter(fileName).
The FileReader and FileWriter constructors instantiate FileInputStream and FileOutputStream,
again causing garbage collection issues while finalizer methods are called.
``` ```
//PrimaryPrefix/AllocationExpression/ClassOrInterfaceType[ //PrimaryPrefix/AllocationExpression/ClassOrInterfaceType[
typeof(@Image, 'java.io.FileInputStream', 'FileInputStream') typeof(@Image, 'java.io.FileInputStream', 'FileInputStream')
@ -138,32 +134,23 @@ again causing garbage collection issues while finalizer methods are called.
**Example(s):** **Example(s):**
``` java ``` java
public class Sample {
// these instantiations cause garbage collection pauses, even if properly closed // these instantiations cause garbage collection pauses, even if properly closed
public void badMethods( ) {
FileInputStream fis = new FileInputStream(fileName); FileInputStream fis = new FileInputStream(fileName);
FileOutputStream fos = new FileOutputStream(fileName); FileOutputStream fos = new FileOutputStream(fileName);
FileReader fr = new FileReader(fileName); FileReader fr = new FileReader(fileName);
FileWriter fw = new FileWriter(fileName); FileWriter fw = new FileWriter(fileName);
}
// the following instantiations help prevent Garbage Collection pauses, no finalization // the following instantiations help prevent Garbage Collection pauses, no finalization
public void goodMethods( ) {
try(InputStream is = Files.newInputStream(Paths.get(fileName))) { try(InputStream is = Files.newInputStream(Paths.get(fileName))) {
} }
try(OutputStream os = Files.newOutputStream(Paths.get(fileName))) { try(OutputStream os = Files.newOutputStream(Paths.get(fileName))) {
} }
try(BufferedReader br = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) { try(BufferedReader br = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) {
} }
try(BufferedWriter wr = Files.newBufferedWriter(Paths.get(fileName), StandardCharsets.UTF_8)) { try(BufferedWriter wr = Files.newBufferedWriter(Paths.get(fileName), StandardCharsets.UTF_8)) {
} }
}
}
``` ```
**Use this rule by referencing it:** **Use this rule by referencing it:**