sonar-bugs

2019年1月22日 作者 刘剑

new BigDecimal(Stringvalue) 或 BigDecimal.valueof( double value)
http://192.168.8.169:9000/project/issues?id=com.yangshan.eship%3Ayangshan-parent&open=AWdzK2MZP3Y1Ty5B_sj2&resolved=false&types=BUG

java Formatter 为什么要close
http://192.168.8.169:9000/project/issues?id=com.yangshan.eship%3Ayangshan-parent&open=AWcbkMCphkGIDtAVvLsv&resolved=false&types=BUG


参照: https://blog.csdn.net/quinnnorris/article/details/54614446

为什么要显式转换

http://192.168.8.169:9000/project/issues?id=com.yangshan.eship%3Ayangshan-parent&open=AWcbkL94hkGIDtAVvLk4&resolved=false&types=BUG

  }catch (InterruptedException e) {
    LOGGER.log(Level.WARN, "Interrupted!", e);
    // Restore interrupted state...
    Thread.currentThread().interrupt();
  }

long a = 10 * 100 * 1000 * 1000 * 1000L;
// 1000000000000

long a = 10 * 100 * 1000 * 1000 * 1000;
// -727379968

@Test
public void testRandom(){
        Random random1 = new Random(1);
        Random random2 = new Random(1);

        for (int i = 0; i < 3; i++) {

            log.debug("random1随机数:{}", random1.nextInt(100));
            log.debug("random2随机数:{}", random2.nextInt(100));
        }
}
// 每次输出都一样
random1随机数:85
random2随机数:85
random1随机数:88
random2随机数:88
random1随机数:47
random2随机数:47

如果想避免出现随机数字相同的情况,则需要注意,无论项目中需要生成多少个随机数字,都只使用一个Random对象即可, 即单例工程模型。

直接使用 org.apache.commons.lang3.RandomUtils

private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
线程不安全,所以要使用时new出来

折中使用, DateUtil 绑定到线程上

//Noncompliant Code Example
if (x < 0)
  new IllegalArgumentException("x must be nonnegative");

//Compliant Solution
if (x < 0)
  throw new IllegalArgumentException("x must be nonnegative");