Browse Source

无JIRA任务,sonar问题修复

* commit '08d97d7f577e97e35ffa91b0c98d6853cc2146df':
  不要重复close
  close的一些细节
  无JIRA任务,sonar问题修复
research/10.0
Alex.Sung 5 years ago
parent
commit
0847dd02ef
  1. 11
      designer-base/src/main/java/com/fr/design/DesignerEnvManager.java
  2. 11
      designer-base/src/main/java/com/fr/design/RestartHelper.java
  3. 36
      designer-base/src/main/java/com/fr/design/extra/PluginUtils.java
  4. 11
      designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java
  5. 10
      designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java
  6. 8
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/CodeTemplateManager.java

11
designer-base/src/main/java/com/fr/design/DesignerEnvManager.java

@ -315,8 +315,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
} }
private void createEnvFile(File envFile) { private void createEnvFile(File envFile) {
FileWriter fileWriter = null;
try { try {
FileWriter fileWriter = new FileWriter(envFile); fileWriter = new FileWriter(envFile);
File oldEnvFile = new File(ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "6-1" + "Env.xml"); File oldEnvFile = new File(ProductConstants.getEnvHome() + File.separator + ProductConstants.APP_NAME + "6-1" + "Env.xml");
File envFile80 = new File(getEnvHome(VERSION_80) + File.separator + getEnvFile().getName()); File envFile80 = new File(getEnvHome(VERSION_80) + File.separator + getEnvFile().getName());
if (oldEnvFile.exists()) { if (oldEnvFile.exists()) {
@ -332,11 +333,19 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
Utils.copyCharTo(stringReader, fileWriter); Utils.copyCharTo(stringReader, fileWriter);
stringReader.close(); stringReader.close();
} }
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
if (null != fileWriter) {
try {
fileWriter.close(); fileWriter.close();
} catch (IOException e) { } catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }
}
}
private static String getEnvHome(String version) { private static String getEnvHome(String version) {
String userHome = System.getProperty("user.home"); String userHome = System.getProperty("user.home");

11
designer-base/src/main/java/com/fr/design/RestartHelper.java

@ -154,12 +154,12 @@ public class RestartHelper {
deleteWhenDebug(); deleteWhenDebug();
return; return;
} }
RandomAccessFile randomAccessFile = null;
try { try {
try { try {
File restartLockFile = new File(StableUtils.pathJoin(StableUtils.getInstallHome(), "restart.lock")); File restartLockFile = new File(StableUtils.pathJoin(StableUtils.getInstallHome(), "restart.lock"));
StableUtils.makesureFileExist(restartLockFile); StableUtils.makesureFileExist(restartLockFile);
RandomAccessFile randomAccessFile = new RandomAccessFile(restartLockFile,"rw"); randomAccessFile = new RandomAccessFile(restartLockFile,"rw");
FileChannel restartLockFC = randomAccessFile.getChannel(); FileChannel restartLockFC = randomAccessFile.getChannel();
FileLock restartLock = restartLockFC.tryLock(); FileLock restartLock = restartLockFC.tryLock();
if(restartLock == null) { if(restartLock == null) {
@ -176,6 +176,13 @@ public class RestartHelper {
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally { } finally {
try {
if (null != randomAccessFile) {
randomAccessFile.close();
}
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
DesignerContext.getDesignerFrame().exit(); DesignerContext.getDesignerFrame().exit();
} }
} }

36
designer-base/src/main/java/com/fr/design/extra/PluginUtils.java

@ -6,6 +6,7 @@ import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.plugin.PluginVerifyException;
import com.fr.plugin.basic.version.Version; import com.fr.plugin.basic.version.Version;
import com.fr.plugin.basic.version.VersionIntervalFactory; import com.fr.plugin.basic.version.VersionIntervalFactory;
import com.fr.plugin.context.PluginContext; import com.fr.plugin.context.PluginContext;
@ -18,6 +19,7 @@ import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.JOptionPane;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -82,14 +84,17 @@ public class PluginUtils {
return jsonArray.toString(); return jsonArray.toString();
} }
public static void downloadShopScripts(String id, Process<Double> p) throws Exception { public static boolean downloadShopScripts(String id, Process<Double> p) {
InputStream reader = null;
FileOutputStream writer = null;
try {
HttpClient httpClient = new HttpClient(getDownloadPath(id)); HttpClient httpClient = new HttpClient(getDownloadPath(id));
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
int totalSize = httpClient.getContentLength(); int totalSize = httpClient.getContentLength();
InputStream reader = httpClient.getResponseStream(); reader = httpClient.getResponseStream();
String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE); String temp = StableUtils.pathJoin(PluginConstants.DOWNLOAD_PATH, PluginConstants.TEMP_FILE);
StableUtils.makesureFileExist(new File(temp)); StableUtils.makesureFileExist(new File(temp));
FileOutputStream writer = new FileOutputStream(temp); writer = new FileOutputStream(temp);
byte[] buffer = new byte[PluginConstants.BYTES_NUM]; byte[] buffer = new byte[PluginConstants.BYTES_NUM];
int bytesRead = 0; int bytesRead = 0;
int totalBytesRead = 0; int totalBytesRead = 0;
@ -100,11 +105,32 @@ public class PluginUtils {
totalBytesRead += bytesRead; totalBytesRead += bytesRead;
p.process(totalBytesRead / (double) totalSize); p.process(totalBytesRead / (double) totalSize);
} }
} else {
throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error"));
}
} catch (PluginVerifyException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return false;
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
} finally {
closeStream(reader, writer);
}
return true;
}
private static void closeStream(InputStream reader, FileOutputStream writer){
try {
if (null != reader) {
reader.close(); reader.close();
}
if (null != writer) {
writer.flush(); writer.flush();
writer.close(); writer.close();
} else { }
throw new com.fr.plugin.PluginVerifyException(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Connect_Server_Error")); } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
} }

11
designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java

@ -259,21 +259,12 @@ public class WebViewDlgHelper {
new SwingWorker<Boolean, Void>() { new SwingWorker<Boolean, Void>() {
@Override @Override
protected Boolean doInBackground() throws Exception { protected Boolean doInBackground() throws Exception {
try { return PluginUtils.downloadShopScripts(scriptsId, new Process<Double>() {
PluginUtils.downloadShopScripts(scriptsId, new Process<Double>() {
@Override @Override
public void process(Double integer) { public void process(Double integer) {
// 这个注释毫无意义,就是为了通过SonarQube // 这个注释毫无意义,就是为了通过SonarQube
} }
}); });
} catch (PluginVerifyException e) {
JOptionPane.showMessageDialog(null, e.getMessage(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Warning"), JOptionPane.ERROR_MESSAGE);
return false;
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return false;
}
return true;
} }
@Override @Override

10
designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java

@ -174,7 +174,7 @@ public final class FunctionConstants {
jarPath = StringUtils.perfectStart(jarPath, "/"); jarPath = StringUtils.perfectStart(jarPath, "/");
} }
ZipFile zip; ZipFile zip = null;
try { try {
zip = new ZipFile(jarPath); zip = new ZipFile(jarPath);
Enumeration entries = zip.entries(); Enumeration entries = zip.entries();
@ -193,6 +193,14 @@ public final class FunctionConstants {
} }
} catch (IOException e) { } catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
if(null != zip){
try {
zip.close();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
} }
} else { } else {
File dir = new File(filePath); File dir = new File(filePath);

8
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/CodeTemplateManager.java

@ -276,8 +276,9 @@ public class CodeTemplateManager {
temp.addAll(templates); temp.addAll(templates);
for (int i=0; i<newCount; i++) { for (int i=0; i<newCount; i++) {
XMLDecoder d = null;
try { try {
XMLDecoder d = new XMLDecoder(new BufferedInputStream( d = new XMLDecoder(new BufferedInputStream(
new FileInputStream(files[i]))); new FileInputStream(files[i])));
Object obj = d.readObject(); Object obj = d.readObject();
if (!(obj instanceof CodeTemplate)) { if (!(obj instanceof CodeTemplate)) {
@ -285,12 +286,15 @@ public class CodeTemplateManager {
files[i].getAbsolutePath()); files[i].getAbsolutePath());
} }
temp.add((CodeTemplate)obj); temp.add((CodeTemplate)obj);
d.close();
} catch (/*IO, NoSuchElement*/Exception e) { } catch (/*IO, NoSuchElement*/Exception e) {
// NoSuchElementException can be thrown when reading // NoSuchElementException can be thrown when reading
// an XML file not in the format expected by XMLDecoder. // an XML file not in the format expected by XMLDecoder.
// (e.g. CodeTemplates in an old format). // (e.g. CodeTemplates in an old format).
e.printStackTrace(); e.printStackTrace();
} finally {
if(null != d){
d.close();
}
} }
} }
templates = temp; templates = temp;

Loading…
Cancel
Save