You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Lennart Jörelid <le...@gmail.com> on 2015/10/22 08:00:46 UTC

Maven Checkstyle Plugin - IllegalType rule configuration not working

Hello all,

I’m using Maven-Checkstyle-Plugin version 2.17 (with Checkstyle 6.11.2).

I’m trying to get the Checkstyle plugin to break the build whenever one of
the pre-JDK8 date/time types are used in the *public API* (but not the
internal state) of a class. This implies that applications can use properly
working date/time classes while making ORM frameworks adhere to the JPA
standard - which works properly with pre-JDK8 date/time types. The pattern
becomes:

*Example:*

@NotNull
@Basic(optional = false)
@Column(nullable = false)
@Temporal(value = TemporalType.TIMESTAMP)
private Calendar startTime;

… with the corresponding getter …

/**
 * @return The start time of the Activity.
 */
public ZonedDateTime getStartTime() {
   return ZonedDateTime.ofInstant(startTime.toInstant(),
startTime.getTimeZone().toZoneId());
}


*Checkstyle configuration:*

Rule configuration should be simple enough, according to the documentation.
Simply is the property ”tokens” to set the illegal types to be used as
PARAMETER_DEF and METHOD_DEF only (and hence not VARIABLE_DEF), and the
private Calendar startTime should pass validation. The configuration is
shown below.

<module name="IllegalType">
    <property name="severity" value="error"/>
    <property name="tokens" value="PARAMETER_DEF,METHOD_DEF"/>
    <property name="validateAbstractClassNames" value="true"/>
    <property name="illegalClassNames"
              value="java.util.GregorianCalendar, java.util.Calendar,
java.util.Date, java.util.Vector, java.util.Properties"/>
    <property name="format" value="thisShouldMatchNothingReally"/>
</module>

However, when running the check, maven-checkstyle-plugin breaks the build
on the startTime variable (which should correspond to a VARIABLE_DEF …
which is not present in the configuration). What am I missing here? The
Checkstyle plugin seems to ignore the ”tokens” property:

[ERROR]
src/main/java/se/mithlond/services/organisation/model/activity/Activity.java:[155,17]
(coding) IllegalType: Declaring *variables,* return values or parameters of
type 'Calendar' is not allowed.

-- 

--
+==============================+
| Bästa hälsningar,
| [sw. "Best regards"]
|
| Lennart Jörelid
| EAI Architect & Integrator
|
| jGuru Europe AB
| Mölnlycke - Kista
|
| Email: lj@jguru.se
| URL:   www.jguru.se
| Phone
| (skype):    jgurueurope
| (intl):     +46 708 507 603
| (domestic): 0708 - 507 603
+==============================+

Re: Maven Checkstyle Plugin - IllegalType rule configuration not working

Posted by Lennart Jörelid <le...@gmail.com>.
Never mind, folks.

Just ignore this comment - it was caused by a bug in Checkstyle itself, not
the plugin.

https://github.com/checkstyle/checkstyle/pull/2416 for those that want to
check out the details.


2015-10-22 8:00 GMT+02:00 Lennart Jörelid <le...@gmail.com>:

> Hello all,
>
> I’m using Maven-Checkstyle-Plugin version 2.17 (with Checkstyle 6.11.2).
>
> I’m trying to get the Checkstyle plugin to break the build whenever one of
> the pre-JDK8 date/time types are used in the *public API* (but not the
> internal state) of a class. This implies that applications can use properly
> working date/time classes while making ORM frameworks adhere to the JPA
> standard - which works properly with pre-JDK8 date/time types. The pattern
> becomes:
>
> *Example:*
>
> @NotNull
> @Basic(optional = false)
> @Column(nullable = false)
> @Temporal(value = TemporalType.TIMESTAMP)
> private Calendar startTime;
>
> … with the corresponding getter …
>
> /**
>  * @return The start time of the Activity.
>  */
> public ZonedDateTime getStartTime() {
>    return ZonedDateTime.ofInstant(startTime.toInstant(), startTime.getTimeZone().toZoneId());
> }
>
>
> *Checkstyle configuration:*
>
> Rule configuration should be simple enough, according to the
> documentation. Simply is the property ”tokens” to set the illegal types to
> be used as PARAMETER_DEF and METHOD_DEF only (and hence not VARIABLE_DEF),
> and the private Calendar startTime should pass validation. The
> configuration is shown below.
>
> <module name="IllegalType">
>     <property name="severity" value="error"/>
>     <property name="tokens" value="PARAMETER_DEF,METHOD_DEF"/>
>     <property name="validateAbstractClassNames" value="true"/>
>     <property name="illegalClassNames"
>               value="java.util.GregorianCalendar, java.util.Calendar, java.util.Date, java.util.Vector, java.util.Properties"/>
>     <property name="format" value="thisShouldMatchNothingReally"/>
> </module>
>
> However, when running the check, maven-checkstyle-plugin breaks the build
> on the startTime variable (which should correspond to a VARIABLE_DEF …
> which is not present in the configuration). What am I missing here? The
> Checkstyle plugin seems to ignore the ”tokens” property:
>
> [ERROR]
> src/main/java/se/mithlond/services/organisation/model/activity/Activity.java:[155,17]
> (coding) IllegalType: Declaring *variables,* return values or parameters
> of type 'Calendar' is not allowed.
>
> --
>
> --
> +==============================+
> | Bästa hälsningar,
> | [sw. "Best regards"]
> |
> | Lennart Jörelid
> | EAI Architect & Integrator
> |
> | jGuru Europe AB
> | Mölnlycke - Kista
> |
> | Email: lj@jguru.se
> | URL:   www.jguru.se
> | Phone
> | (skype):    jgurueurope
> | (intl):     +46 708 507 603
> | (domestic): 0708 - 507 603
> +==============================+
>
>


-- 

--
+==============================+
| Bästa hälsningar,
| [sw. "Best regards"]
|
| Lennart Jörelid
| EAI Architect & Integrator
|
| jGuru Europe AB
| Mölnlycke - Kista
|
| Email: lj@jguru.se
| URL:   www.jguru.se
| Phone
| (skype):    jgurueurope
| (intl):     +46 708 507 603
| (domestic): 0708 - 507 603
+==============================+