This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue checkstyle#3348: add validation of try with resources to the Lo…
…calFinalVariableName check
- Loading branch information
vasilyeva
committed
May 7, 2017
1 parent
5e0ab75
commit eab8d58
Showing
5 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...ckstyle/checks/naming/localfinalvariablename/InputLocalFinalVariableNameTryResources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.puppycrawl.tools.checkstyle.checks.naming.localfinalvariablename; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import java.util.PropertyResourceBundle; | ||
import java.util.zip.ZipFile; | ||
|
||
/** | ||
* Contains test cases regarding checking local | ||
* final variable name in try-with-resources statement: | ||
* | ||
* @author Valeria Vasylieva | ||
**/ | ||
public class InputLocalFinalVariableNameTryResources { | ||
|
||
void method() throws Exception { | ||
final String fileName = "Test"; | ||
final BufferedReader br = new BufferedReader(new InputStreamReader( | ||
new FileInputStream(fileName), StandardCharsets.UTF_8)); | ||
try { | ||
} | ||
finally { | ||
br.close(); | ||
} | ||
} | ||
|
||
void method2() throws Exception { | ||
final String fileName = "Test"; | ||
try (BufferedReader br = new BufferedReader(new InputStreamReader( | ||
new FileInputStream(fileName), StandardCharsets.UTF_8))) { | ||
} | ||
finally { | ||
|
||
} | ||
} | ||
|
||
void method3() throws Exception { | ||
final String fileName = "Test"; | ||
try (final BufferedReader BR = new BufferedReader(new InputStreamReader( | ||
new FileInputStream(fileName), StandardCharsets.UTF_8))) { | ||
} | ||
finally { | ||
|
||
} | ||
} | ||
|
||
void method4() throws Exception { | ||
final String fileName = "Test"; | ||
try (BufferedReader BR = new BufferedReader(new InputStreamReader( | ||
new FileInputStream(fileName), StandardCharsets.UTF_8)); | ||
ZipFile zf = new ZipFile(fileName)) { | ||
} | ||
finally { | ||
|
||
} | ||
} | ||
|
||
void method5() throws Exception { | ||
final String fileName = "Test"; | ||
try (BufferedReader BR = new BufferedReader(new InputStreamReader( | ||
new FileInputStream(fileName), StandardCharsets.UTF_8)); | ||
ZipFile ZF = new ZipFile(fileName)) { | ||
} | ||
finally { | ||
|
||
} | ||
} | ||
|
||
void method6() throws Exception { | ||
String srcDir = System.getProperty("test.src", "."); | ||
try (FileInputStream fis8859_1 = new FileInputStream(new File(srcDir, "Bug6204853.properties")); | ||
FileInputStream fisUTF8 = new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties")); | ||
InputStreamReader isrutf8 = new InputStreamReader(fisUTF8, "UTF-8")) { | ||
PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrutf8); | ||
PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1); | ||
String[] arrayUtf8 = {"1", "2", "3"}; | ||
String[] array = {"key1", "key2"}; | ||
if (!Arrays.equals(arrayUtf8, array)) { | ||
throw new RuntimeException("Error message"); | ||
} | ||
} catch (IOException ioe) { | ||
throw new RuntimeException(ioe); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters