Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#478 IllegalType check with illegalClassNames = false positive

release_1.0
closed
nobody
5
2013-12-09
2007-04-17
No

here is the definition of our check:

    <module name="IllegalType">
      <property name="severity" value="error"/>
      <property name="id" value="IllegalTypeDate"/>
      <property name="illegalClassNames" value="java.sql.Date,java.sql.Time,java.sql.Timestamp,java.util.Date,java.util.Calendar,java.util.GregorianCalendar,java.util.TimeZone,java.util.SimpleTimeZone,java.text.SimpleDateFormat,java.text.DateFormat"/>
      <property name="format" value="^(.*[\\.])?Mock.*$"/>
    </module>

Unfortunately, this check is positive if we use any class in the classpath that have the same file name than the classes specified.

for instance, we have a jar in the classpath containing a class with the canonical name : test.Calendar,

if we use this class like the following:

package test.mytest;
import test.Calendar;
public class MyClass {

   Calendar cal = AnObject.getInstance().getTestCalendar();
   java.util.Date date = null;

}

We get a false positive return for the illegalTypeCheck like this:

Declaring variables, return values or parameters of type 'Calendar' is not allowed.

Observe that for some errors, the illegalTypeCheck returns
Declaring variables, return values or parameters of type 'java.util.Date' is not allowed.

Notice also that test.Calendar does not extend nor use in any way the specified java.util.Calendar.

Discussion

  • Logged In: YES
    user_id=1771547
    Originator: YES

    note that I'm using Checkstyle version 4.3!

     
  • Roman Ivanov
    Roman Ivanov
    2013-12-09

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,12 +1,13 @@
     here is the definition of our check:
    
    +~~~~~~
         <module name="IllegalType">
           <property name="severity" value="error"/>
           <property name="id" value="IllegalTypeDate"/>
           <property name="illegalClassNames" value="java.sql.Date,java.sql.Time,java.sql.Timestamp,java.util.Date,java.util.Calendar,java.util.GregorianCalendar,java.util.TimeZone,java.util.SimpleTimeZone,java.text.SimpleDateFormat,java.text.DateFormat"/>
           <property name="format" value="^(.*[\\.])?Mock.*$"/>
         </module>
    -
    +~~~~~~
    
     Unfortunately, this check is positive if we use any class  in the classpath that have the same file name than the classes specified.
    
    @@ -14,6 +15,7 @@
    
     if we use this class like the following:
    
    +~~~~~~
     package test.mytest;
     import test.Calendar;
     public class MyClass {
    @@ -22,6 +24,7 @@
        java.util.Date date = null;
    
     }
    +~~~~~~
    
     We get a false positive return for the illegalTypeCheck like this:
    
    • Group: --> release_1.0
     
  • Roman Ivanov
    Roman Ivanov
    2013-12-09

    • status: open --> closed