8

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

2 Answers2

7

This seems to be a bug in PMD 4.2.6.

SourceForge-Link:
http://sourceforge.net/projects/pmd/forums/forum/188192/topic/4781145

oers
  • 18,436
  • 13
  • 66
  • 75
4

Relevant bugs from the project. This was fixed in 5.X of PMD. It is also in the 3.0.1 version of the PMD maven plugin.

I saw this question before I found the bugs. Maybe this'll help the next coder.

Jason
  • 81
  • 5