---
title: "findBugs记录"
author: "fourfire"
date: "2010-04-07T08:22:36Z"
tags: []
categories: ["非技术"]
slug: "findbugs"
draft: false
lastmod: "2010-04-07T08:22:36Z"
id: 635289
url: "https://fourfire.iteye.com/blog/635289"
---

1 在0-n之间取随机数，使用
java.util.Random r=new java.util.Random();
r.nextInt(n);
而不使用
(int)(r.nextDouble() * n)
If r is a java.util.Random, you can generate a random number from 0 to n-1 using r.nextInt(n), rather than using (int)(r.nextDouble() * n). 
2 在实例中修改静态类的属性
public void process(File fs) {
		UtilTools.rootPath = "d:/tmp/";
...
This instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally bad practice