Question:
Why the maven PMD plugin is giving me the following warning for the line of code below: Warning:
Avoid using java.lang.ThreadGroup; it is not thread safe
Code (second line):
Calendar cal = Calendar.getInstance();
java.sql.Date endDate = new java.sql.Date(cal.getTime().getTime());
Context:
I have this confit a java.sql.Date instantiation:
public class XYZServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException {
Connection conn = null;
CallableStatement stmt = null;
try {
conn = ...
...
Calendar cal = Calendar.getInstance();
java.sql.Date endDate = new java.sql.Date(cal.getTime().getTime());
...
} catch ...
}finally {
try {
stmt.close();
conn.close();
} catch(Exception e) {}
}
}
}
The line reported by PMD is
java.sql.Date endDate = new java.sql.Date(cal.getTime().getTime());
And the message is:
Avoid using java.lang.ThreadGroup; it is not thread safe