Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 1.9.0 webank sonarfix #608

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codecheck.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
linkis-commons/linkis-common/src/main/java/org/apache/linkis/common/utils/DESUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public double toBytes(long d) {
if (d < 0) {
throw new IllegalArgumentException("Negative size value. Size must be positive: " + d);
}
return d * multiplier;
return (double) d * multiplier;
}

public long toKiB(long d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,12 @@ class CustomMonthType(date: String, std: Boolean = true, isEnd: Boolean = false)

def -(months: Int): String = {
val dateFormat = DateTypeUtils.dateFormatLocal.get()
if (std) {
DateTypeUtils.getMonth(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), -months))
} else {
DateTypeUtils.getMonth(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), -months))
}
DateTypeUtils.getMonth(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), -months))
}

def +(months: Int): String = {
val dateFormat = DateTypeUtils.dateFormatLocal.get()
if (std) {
DateTypeUtils.getMonth(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), months))
} else {
DateTypeUtils.getMonth(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), months))
}
DateTypeUtils.getMonth(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), months))
}

override def toString: String = {
Expand All @@ -111,20 +103,12 @@ class CustomMonType(date: String, std: Boolean = true, isEnd: Boolean = false) {

def -(months: Int): String = {
val dateFormat = DateTypeUtils.dateFormatMonLocal.get()
if (std) {
DateTypeUtils.getMon(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), -months))
} else {
DateTypeUtils.getMon(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), -months))
}
DateTypeUtils.getMon(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), -months))
}

def +(months: Int): String = {
val dateFormat = DateTypeUtils.dateFormatMonLocal.get()
if (std) {
DateTypeUtils.getMon(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), months))
} else {
DateTypeUtils.getMon(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), months))
}
DateTypeUtils.getMon(std, isEnd, DateUtils.addMonths(dateFormat.parse(date), months))
}

override def toString: String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public static void checkStatus() {
LOG.info("CurrentUser: " + curUsr);
if (curUsr == null) {
LOG.info("CurrentUser is null");
throw new Exception("CurrentUser is null");
taoran1250 marked this conversation as resolved.
Show resolved Hide resolved
} else {
LOG.info("CurrentUser is not null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.linkis.protocol.util;

import java.util.AbstractMap;
import java.util.Objects;

public class ImmutablePair<K, V> {

Expand Down Expand Up @@ -53,6 +54,11 @@ public boolean equals(Object o) {
}
}

@Override
public int hashCode() {
return Objects.hashCode(entry);
}

private boolean eq(Object o1, Object o2) {
if (null != o1 && null != o2) {
return o1.equals(o2);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ public static <T> String serialize(T obj) {

public static <T> T deserialize(String str, Class<T> clazz) {
Schema<T> schema = getSchema(clazz);
T obj = schema.newMessage();
ProtostuffIOUtil.mergeFrom(toByteArray(str), obj, schema);
T obj = null;
if (schema != null) {
obj = schema.newMessage();
ProtostuffIOUtil.mergeFrom(toByteArray(str), obj, schema);
}
return obj;
}

Expand Down Expand Up @@ -93,7 +96,7 @@ public static byte[] toByteArray(String hexString) {
for (int i = 0; i < byteArray.length; i++) {
byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 0xff);
byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 0xff);
byteArray[i] = (byte) (high << 4 | low);
byteArray[i] = (byte) (high << 4 | low); // NOSONAR
k += 2;
}
return byteArray;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static List<List<String>> getExcelTitle(
} else {
res = XlsxUtils.getBasicInfo(in, file);
}
if (res == null && res.size() < 2) {
if (res == null || res.size() < 2) {
throw new Exception("There is a problem with the file format(文件格式有问题)");
}
List<String> headerType = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ public boolean copy(String origin, String dest) throws IOException {
setOwner(new FsPath(dest), user, null);
}
} catch (Throwable e) {
file.delete();
if (!file.delete()) {
throw new IOException("File delete failed!");
}
if (e instanceof IOException) {
throw (IOException) e;
} else {
Expand Down Expand Up @@ -383,14 +385,18 @@ public boolean create(String dest) throws IOException {
if (!isOwner(file.getParent())) {
throw new IOException("you have on permission to create file " + dest);
}
file.createNewFile();
if (!file.createNewFile()) {
throw new IOException("create new file error! path:" + dest);
}
try {
setPermission(new FsPath(dest), this.getDefaultFilePerm());
if (!user.equals(getOwner(dest))) {
setOwner(new FsPath(dest), user, null);
}
} catch (Throwable e) {
file.delete();
if (!file.delete()) {
throw new IOException("delete file error!");
}
if (e instanceof IOException) {
throw (IOException) e;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private Map<String, String> getCsvInfo(InputStream in, boolean escapeQuotes, boo
String[][] column = null;
// fix csv file with utf-8 with bom chart[&#xFEFF]
BOMInputStream bomIn = new BOMInputStream(in, false); // don't include the BOM
BufferedReader reader = new BufferedReader(new InputStreamReader(bomIn, "utf-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(bomIn, "utf-8")); // NOSONAR

String header = reader.readLine();
if (StringUtils.isEmpty(header)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public ParamKeyMapper() {
}

public ParamKeyMapper(Map<String, String> mapperRules) {
mapperRules = new HashMap<>();
initMapperRules(mapperRules);
initMapperRules(new HashMap<>());
}

/** Executor should overwrite init() method to set key to key mapping */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Map<String, String> convert(String from) {
return null;
}
Map<String, String> paraMap = new HashMap<>();
String[] arr = from.trim().split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
String[] arr = from.trim().split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1); // NOSONAR
for (String prop : arr) {
prop = prop.trim();
int index = prop.indexOf("=");
Expand Down Expand Up @@ -97,7 +97,7 @@ public SpecialMap<String, String> convert(String from) {
return null;
}
SpecialMap<String, String> paraMap = new SpecialMap<>();
String[] arr = from.trim().split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
String[] arr = from.trim().split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1); // NOSONAR
for (String prop : arr) {
prop = prop.trim();
int index = prop.indexOf("=");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String toString() {
.append(
defaultValue.getClass().isArray()
? StringUtils.join((Object[]) defaultValue, ", ")
: (defaultValue == null ? "" : defaultValue.toString()))
: defaultValue.toString())
.append(System.lineSeparator());

sb.append("\t\toptional:").append(isOptional());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String toString() {
.append(
defaultValue.getClass().isArray()
? StringUtils.join((Object[]) defaultValue, ", ")
: (defaultValue == null ? "" : defaultValue.toString()))
: defaultValue.toString())
.append(System.lineSeparator());

sb.append("\t\toptional:").append(isOptional());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public Properties getProperties() {
"PRP0002", ErrorLevel.ERROR, CommonErrMsg.PropsReaderErr, "Source: " + propsPath, e);
} finally {
try {
in.close();
if (null != in) {
in.close();
}
} catch (Exception ignore) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ public void setOnceJob(SimpleOnceJob onceJob) {
private void panicIfNull(Object obj) {
if (obj == null) {
throw new LinkisClientExecutionException(
"EXE0040",
ErrorLevel.ERROR,
CommonErrMsg.ExecutionErr,
"Instance of " + obj.getClass().getCanonicalName() + " is null");
"EXE0040", ErrorLevel.ERROR, CommonErrMsg.ExecutionErr, "Instance of <Unknown> is null");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,9 @@ public class UJESClientFactory {

private static UJESClient client;

public static UJESClient getReusable(VarAccess stdVarAccess) {
public static synchronized UJESClient getReusable(VarAccess stdVarAccess) {
if (client == null) {
synchronized (UJESClientFactory.class) {
if (client == null) {
client = getNew(stdVarAccess);
}
}
client = getNew(stdVarAccess);
}
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ public Float getJobProgress() {
return null;
}
if (result instanceof JobInfoResult) {
if (((JobInfoResult) result).getRequestPersistTask() != null
&& ((JobInfoResult) result).getRequestPersistTask() != null) {
if (((JobInfoResult) result).getRequestPersistTask() != null) {
return ((JobInfoResult) result).getRequestPersistTask().getProgress();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public static void writeToFile(

if (overWrite || !file.exists()) {
try {
file.createNewFile();
if (!file.createNewFile()) {
throw new PresenterException(
"PST0006",
ErrorLevel.ERROR,
CommonErrMsg.PresentDriverErr,
"Cannot create file for path: " + file.getAbsolutePath());
}
} catch (Exception e) {
throw new PresenterException(
"PST0006",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,10 @@ public static String getProxyUser(
}

public static String readFile(String path) {
try {
File inputFile = new File(path);

InputStream inputStream = new FileInputStream(inputFile);
InputStreamReader iReader = new InputStreamReader(inputStream);
BufferedReader bufReader = new BufferedReader(iReader);

File inputFile = new File(path);
try (InputStream inputStream = new FileInputStream(inputFile);
InputStreamReader iReader = new InputStreamReader(inputStream);
BufferedReader bufReader = new BufferedReader(iReader)) {
StringBuilder sb = new StringBuilder();
StringBuilder line;
while (bufReader.ready()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,16 @@ public static ExecutorService newFixedThreadPool(
return Executors.newFixedThreadPool(threadNum, threadFactory(threadName, isDaemon));
}

public static ThreadPoolExecutor getCachedThreadPoolExecutor() {
public static synchronized ThreadPoolExecutor getCachedThreadPoolExecutor() {
if (cachedThreadPool == null) {
synchronized (SchedulerManager.class) {
if (cachedThreadPool == null) {
cachedThreadPool = newCachedThreadPool(THREAD_NUM, THREAD_NAME, IS_DEAMON);
}
}
cachedThreadPool = newCachedThreadPool(THREAD_NUM, THREAD_NAME, IS_DEAMON);
}
return cachedThreadPool;
}

public static ExecutorService getFixedThreadPool() {
public static synchronized ExecutorService getFixedThreadPool() {
if (fixedThreadPool == null) {
synchronized (SchedulerManager.class) {
if (fixedThreadPool == null) {
fixedThreadPool = newFixedThreadPool(THREAD_NUM, THREAD_NAME, IS_DEAMON);
}
}
fixedThreadPool = newFixedThreadPool(THREAD_NUM, THREAD_NAME, IS_DEAMON);
}
return fixedThreadPool;
}
Expand Down
Loading
Loading