赞
踩
cast one of the operands of this multiplication operation to a "long"
long l=12*60*60
long l=12L*60*60
cast one of the operands of this division operation to a "double"
Prevent "int" promotion by adding "& 0xff" to this expression
byte high = (byte) 0B11010000;
byte low = (byte) 0B01111111;
byte result = (byte) (high << 4 | low);
//(high << 4 | low) 运算完之后会升级为int类型
//直接转换为beye类型,会直接舍弃高位,保留8位低位。效果和 0xff一样的
//这里是SonarQube会进行代码检查而已,本身逻辑没问题
byte high = (byte) 0B11010000;
byte low = (byte) 0B01111111;
byte result = (byte) ((high << 4 | low) & 0xff);
correct one of the identical sub-expressions on both sides of operator "||"
remove the boxing of "byteint"
int byteint= Integer.parseInt(swap,16) & 0xFF;
b[j] = new Integer(byteint).byteValue();
int byteint= Integer.parseInt(swap,16) & 0xFF;
b[j] = byteint.byteValue();
remove the boxing to "Double"
public static void main(String[] args) {
Double record = 2.58493128;
Long longValue = Double.valueOf(record * Math.pow(10, 8)).longValue();
System.out.println(longValue);
}
public static void main(String[] args) {
Double record = 2.58493128;
Long longValue = (long)(record * Math.pow(10, 8));
System.out.println(longValue);
}
introduce a new variable instead of reusing the parameter "row"
public int queryAdd (int row,int b){
row=mapper.queryCount();
return row+b;
}
public int queryAdd (int row,int b){
a=mapper.queryCount();
return a+b;
}
Use "BigDecimal.valueOf" instead
BigDecimal dataSize = new BigDecimal(new Double(0));
BigDecimal dataSize = BigDecimal.valueOf(0);
Use try-with-resources or close this "BufferedReader" in a "finally" clause.
try{
FileInputStream fileInput=new FileInputStream("C:\\Users\\ljj\\Desktop\\test.txt");
}catch (Exception e){
e.printStackTrace();
}
//方式一
FileInputStream fileInput=null;
try{
fileInput=new FileInputStream("C:\\Users\\ljj\\Desktop\\test.txt");
}catch (Exception e){
e.printStackTrace();
}finally {
if (fileInput!=null){
fileInput.close();
}
}
//方式二,简洁
try(FileInputStream fileInput=new FileInputStream("C:\\Users\\ljj\\Desktop\\test.txt")){
}catch (Exception e){
e.printStackTrace();
}
remove this throw statement from this finally block.
finally{
try{
reader.close;
}catch (IOException e){
throw e;
}
}
finally{
try{
reader.close;
}catch (IOException e){
}
}
remove this return statement from this finally block
//单位某个人才写的代码,把return写进finally。作者发现catch模块虽然重新抛出了异常,但是因为finally会正常返回,catch抛出的异常失效
static String test() throws RuntimeException{
try{
int i=1/0;
System.out.println(i);
}catch (Exception e){
throw new RuntimeException("运行时异常");
}finally {
return "finally返回";
}
}
static String test() throws RuntimeException{
try{
int i=1/0;
System.out.println(i);
}catch (Exception e){
return "finally返回";
}
return "正常运行";
}
either re-interrupt this method or rethrow the "InterruptedException" that can be caught here
try{
Thread.sleep(3000);
}catch (InterruptedException e){
e.printStackTrace();
}
try{
Thread.sleep(3000);
}catch (InterruptedException e){
e.printStackTrace();
Thread.currentThread().interrupt();
}
change this condition so that it does not always evaluate to "true"
//构造函数不存在返回null,只有可能抛出错误
Account account=new AliyunAccount(dgInfo.getDbUsername(),dbInfo.getDbPass());
if(null==account){
log.error("连接阿里云异常")
throw new Exception("连接阿里云异常")
}
Account account=new AliyunAccount(dgInfo.getDbUsername(),dbInfo.getDbPass());
Only the sign of the result should be examined
if(a.compareTo(b)==-1){
}
if(a.compareTo(b)<0){
}
remove this conditional structure or edit its code blocks so that they're not all the same
if(dept.equals("1")){
System.out.println("这里是外联部");
} else if (dept.equals("2")) {
System.out.println("这里是外联部");
}
if(dept.equals("1")){
System.out.println("这里是外联部");
}
this branch can not be reached because the condition duplicates a previous condition in the same sequence of "if/else if" statements
if(dept.equals("外联部")){
System.out.println("这里是外联部");
} else if (dept.equals("外联部")) {
System.out.println("这里是第二个外联部");
}
System.out.println("这里是外联部");
Check the return value of the "read" call to see how many bytes were read
inputStream.read(data)
while(-1 != inputStream.read(data)){
}
do something with the "boolean" value returned by "delete"
if(csvFile.exists()){
csvFile.delete();
}
//解决方案:增加false判断
if(csvFile.exists()){
if (!csvFile.delete()) {
log.error("文件删除失败");
}
}
The return value of "length" must be used
String s = "abcdefg";
s.length();
String s = "abcdefg";
int len = s.length();
update this scope and remove the "systemPath"
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.5.15</version>
<scope>system<scope>
<systemPath>${project.basedir}/libs/hutool-all.jar</systemPath>
</dependency>
Save and re-use this "Random"
Random rand=new Random();
Random rand=new SecureRandom();
Refactor this repetition that can lead to a stack overflow for large inputs
//邮箱地址判断
//提示原因:([-+.]\\w+)* 在表达式里面重复了
Pattern pattern= Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-+.]\\w+)*\\.w+([-+.]\\w+)*$");
Add a type test to this method
public boolean equals(Object obj) {
Student student = (Student) obj;
if (student.getName().equals(this.name)) return true;
return false;
}
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
Student student = (Student) obj;
if (student.getName().equals(this.name)) return true;
return false;
}
this class overrides "equals()" and should therefore also override "hashCode()"
"-1" it not a valid for setting "dayOfMonth"
Calendar calendar = new GregorianCalendar(1900, 0, -1);
Calendar calendar = new GregorianCalendar(1900, 0, 0);
calendar.add(Calendar.DATE, -1);
Make sure that week year "YYYY" is expected here instead of Year "yyyy"
SimpleDateFormat formater = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Make "sdf" an instance variable
public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Remove this "return" statement or make it conditional
public static int maxArray(int a[]){
for (int i : a) {
return i;
}
return 0;
}
public static int maxArray(int a[]){
for (int i : a) {
}
return 0;
}
Throw this exception or remove this useless statement
try{
System.out.println("程序正常执行!");
}catch (Exception e){
System.out.println("程序非正常执行!");
new RuntimeException("程序非正常执行!");
}
try{
System.out.println("程序正常执行!");
}catch (Exception e){
System.out.println("程序非正常执行!");
throw new RuntimeException("程序非正常执行!");
}
either override Object.equals(Object obj),or totally rename the method to prevent any confusion
Change this code to use a stronger protocol
Enablle server certificate validation on this SSL/TLS connextion
@Override
public void checkClientTrusted(X509Certificate[] chain,String authType){
}
Use a secure padding scheme
SSLContext sc=SSLContext.getInstance("SSL")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。