Created
May 11, 2019 01:09
-
-
Save dvmarcilio/57d3e6dcb7c85239ae7e1f2a3f70cdd0 to your computer and use it in GitHub Desktop.
squid:S2095 - False positive
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
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import org.eclipse.core.runtime.IPath; | |
import org.eclipse.ui.internal.WorkbenchPlugin; | |
public class MCVE { | |
static File makeDisplayCopy(File file) { | |
IPath path = WorkbenchPlugin.getDefault().getDataLocation(); | |
if (path == null) { | |
return null; | |
} | |
path = path.append(""); | |
File copy = path.toFile(); | |
FileReader in = null; | |
FileWriter out = null; | |
try { | |
in = new FileReader(file); | |
// don't append data, overwrite what was there | |
out = new FileWriter(copy); | |
char buffer[] = new char[4096]; | |
int count; | |
while ((count = in.read(buffer, 0, buffer.length)) > 0) { | |
out.write(buffer, 0, count); | |
} | |
} catch (FileNotFoundException e) { | |
return null; | |
} catch (IOException e) { | |
return null; | |
} finally { | |
try { | |
if (in != null) { | |
in.close(); | |
} | |
if (out != null) { | |
out.close(); | |
} | |
} catch (IOException e) { | |
return null; | |
} | |
} | |
return copy; | |
} | |
static File makeDisplayCopy2(File file) { | |
IPath path = WorkbenchPlugin.getDefault().getDataLocation(); | |
if (path == null) { | |
return null; | |
} | |
path = path.append(""); | |
File copy = path.toFile(); | |
FileReader in = null; | |
FileWriter out = null; | |
try { | |
in = new FileReader(file); | |
// don't append data, overwrite what was there | |
out = new FileWriter(copy); | |
char buffer[] = new char[4096]; | |
int count; | |
while ((count = in.read(buffer, 0, buffer.length)) > 0) { | |
out.write(buffer, 0, count); | |
} | |
} catch (FileNotFoundException e) { | |
return null; | |
} catch (IOException e) { | |
return null; | |
} finally { | |
try { | |
if (out != null) { | |
out.close(); | |
} | |
if (in != null) { | |
in.close(); | |
} | |
} catch (IOException e) { | |
return null; | |
} | |
} | |
return copy; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment