Checkstyle Custom rule fails to instantiate

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Checkstyle Custom rule fails to instantiate

tymieniecki
package softquatrachecks;

import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.checks.CheckUtils;

/**
 *
 *
 * This package provides the custom checks that were required outside
 * of the standard checks provided
 *
 */
public class LoggerAttrCheck extends Check
{
         /**
     *
     * Indicator 7: Logging Mechanisms
     *
     * The Logger must be declared as a static final class attribute
     *
     */
    @Override
    public int[] getDefaultTokens()
    {
        return new int[] {
            TokenTypes.VARIABLE_DEF
        };
    }

    @Override
    public void visitToken(DetailAST aAST)
    {
               
    if(aAST.getType()==TokenTypes.VARIABLE_DEF)
        visitVariableDef(aAST);

    }
    /**
     * Checks type of given variable.
     * @param aAST variable to check.
     */
    private void visitVariableDef(DetailAST aAST)
    {
        checkVariableDefn(aAST);
    }

    /**
     *
     * Checks variable to see if its a Logger and static final
     *      * @param aAST node to check.
     */
    private void checkVariableDefn(DetailAST aAST)
    {
        final DetailAST type = aAST.findFirstToken(TokenTypes.TYPE);
        final FullIdent ident = CheckUtils.createFullType(type);
        if ((ident.getText().equals("Logger"))) {
        if((!aAST.branchContains(TokenTypes.FINAL))||(!aAST.branchContains(TokenTypes.LITERAL_STATIC)))
                        {
    log(type.getLineNo(), type.getColumnNo(),
             "Logger not defined as static final class attribute", type.getText());
                        }    
        }
    }

}
When the rule is processed I get the message:
"Unable to create Checker: cannot initialize module TreeWalker - Unable to instantiate LoggerAttr"

Now my checkstyle_packages.xml file in che checkstyle-5.5 folder is  :
<?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE checkstyle-packages PUBLIC
    "-//Puppy Crawl//DTD Package Names 1.0//EN"
    "http://www.puppycrawl.com/dtds/packages_1_0.dtd">

<checkstyle-packages>
  <package name="softquatrachecks"/>
</checkstyle-packages>

Any Ideas folks
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

Lars Ködderitzsch
Have you tried packaging your package.xml within your extension jar as
described here:
http://checkstyle.sourceforge.net/config.html#Packages
?

HTH, Lars


Am 29.01.2012 17:42, schrieb tymieniecki:

> package softquatrachecks;
>
> import com.puppycrawl.tools.checkstyle.api.Check;
> import com.puppycrawl.tools.checkstyle.api.DetailAST;
> import com.puppycrawl.tools.checkstyle.api.FullIdent;
> import com.puppycrawl.tools.checkstyle.api.TokenTypes;
> import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
>
> /**
>   *
>   *
>   * This package provides the custom checks that were required outside
>   * of the standard checks provided
>   *
>   */
> public class LoggerAttrCheck extends Check
> {
> /**
>       *
>       * Indicator 7: Logging Mechanisms
>       *
>       * The Logger must be declared as a static final class attribute
>       *
>       */
>      @Override
>      public int[] getDefaultTokens()
>      {
>          return new int[] {
>              TokenTypes.VARIABLE_DEF
>          };
>      }
>
>      @Override
>      public void visitToken(DetailAST aAST)
>      {
>
>       if(aAST.getType()==TokenTypes.VARIABLE_DEF)
>           visitVariableDef(aAST);
>
>      }
>      /**
>       * Checks type of given variable.
>       * @param aAST variable to check.
>       */
>      private void visitVariableDef(DetailAST aAST)
>      {
>          checkVariableDefn(aAST);
>      }
>
>      /**
>       *
>       * Checks variable to see if its a Logger and static final
>       *      * @param aAST node to check.
>       */
>      private void checkVariableDefn(DetailAST aAST)
>      {
>          final DetailAST type = aAST.findFirstToken(TokenTypes.TYPE);
>          final FullIdent ident = CheckUtils.createFullType(type);
>          if ((ident.getText().equals("Logger"))) {
>
> if((!aAST.branchContains(TokenTypes.FINAL))||(!aAST.branchContains(TokenTypes.LITERAL_STATIC)))
> {
>     log(type.getLineNo(), type.getColumnNo(),
>              "Logger not defined as static final class attribute",
> type.getText());
> }
>          }
>      }
>
> }
> When the rule is processed I get the message:
> "Unable to create Checker: cannot initialize module TreeWalker - Unable to
> instantiate LoggerAttr"
>
> Now my checkstyle_packages.xml file in che checkstyle-5.5 folder is  :
> <?xml version="1.0" encoding="UTF-8"?>
>
>      <!DOCTYPE checkstyle-packages PUBLIC
>      &quot;-//Puppy Crawl//DTD Package Names 1.0//EN&quot;
>      &quot;http://www.puppycrawl.com/dtds/packages_1_0.dtd&quot;>
>
> <checkstyle-packages>
>    <package name="softquatrachecks"/>
> </checkstyle-packages>
>
> Any Ideas folks
>
>
> --
> View this message in context: http://checkstyle.2069334.n4.nabble.com/Checkstyle-Custom-rule-fails-to-instantiate-tp4338632p4338632.html
> Sent from the CheckStyle - User mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

tymieniecki
Hi Lars,

Sadly yes, but I will double check to ensure it is in the root path

-----Original Message-----
From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 30 January 2012 19:04
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Have you tried packaging your package.xml within your extension jar as
described here:
http://checkstyle.sourceforge.net/config.html#Packages
?

HTH, Lars


Am 29.01.2012 17:42, schrieb tymieniecki:

> package softquatrachecks;
>
> import com.puppycrawl.tools.checkstyle.api.Check;
> import com.puppycrawl.tools.checkstyle.api.DetailAST;
> import com.puppycrawl.tools.checkstyle.api.FullIdent;
> import com.puppycrawl.tools.checkstyle.api.TokenTypes;
> import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
>
> /**
>   *
>   *
>   * This package provides the custom checks that were required outside
>   * of the standard checks provided
>   *
>   */
> public class LoggerAttrCheck extends Check {
> /**
>       *
>       * Indicator 7: Logging Mechanisms
>       *
>       * The Logger must be declared as a static final class attribute
>       *
>       */
>      @Override
>      public int[] getDefaultTokens()
>      {
>          return new int[] {
>              TokenTypes.VARIABLE_DEF
>          };
>      }
>
>      @Override
>      public void visitToken(DetailAST aAST)
>      {
>
>       if(aAST.getType()==TokenTypes.VARIABLE_DEF)
>           visitVariableDef(aAST);
>
>      }
>      /**
>       * Checks type of given variable.
>       * @param aAST variable to check.
>       */
>      private void visitVariableDef(DetailAST aAST)
>      {
>          checkVariableDefn(aAST);
>      }
>
>      /**
>       *
>       * Checks variable to see if its a Logger and static final
>       *      * @param aAST node to check.
>       */
>      private void checkVariableDefn(DetailAST aAST)
>      {
>          final DetailAST type = aAST.findFirstToken(TokenTypes.TYPE);
>          final FullIdent ident = CheckUtils.createFullType(type);
>          if ((ident.getText().equals("Logger"))) {
>
>
if((!aAST.branchContains(TokenTypes.FINAL))||(!aAST.branchContains(TokenType
s.LITERAL_STATIC)))
> {
>     log(type.getLineNo(), type.getColumnNo(),
>              "Logger not defined as static final class
attribute",

> type.getText());
> }
>          }
>      }
>
> }
> When the rule is processed I get the message:
> "Unable to create Checker: cannot initialize module TreeWalker -
> Unable to instantiate LoggerAttr"
>
> Now my checkstyle_packages.xml file in che checkstyle-5.5 folder is  :
> <?xml version="1.0" encoding="UTF-8"?>
>
>      <!DOCTYPE checkstyle-packages PUBLIC
>      &quot;-//Puppy Crawl//DTD Package Names 1.0//EN&quot;
>      &quot;http://www.puppycrawl.com/dtds/packages_1_0.dtd&quot;>
>
> <checkstyle-packages>
>    <package name="softquatrachecks"/>
> </checkstyle-packages>
>
> Any Ideas folks
>
>
> --
> View this message in context:
> http://checkstyle.2069334.n4.nabble.com/Checkstyle-Custom-rule-fails-t
> o-instantiate-tp4338632p4338632.html
> Sent from the CheckStyle - User mailing list archive at Nabble.com.
>
> ----------------------------------------------------------------------
> -------- Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft
> developers is just $99.99! Visual Studio, SharePoint, SQL - plus
> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you
subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>


----------------------------------------------------------------------------
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

tymieniecki
Hi Lars,

I have indeed packaged my check as described even trying both dtd1.0 and
dtd1.3 so as to match the main rules xml file.
Is there any other XML file that may need 'modifying' ?

REgards

-----Original Message-----
From: Mark Tymieniecki [mailto:[hidden email]]
Sent: 30 January 2012 20:30
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Hi Lars,

Sadly yes, but I will double check to ensure it is in the root path

-----Original Message-----
From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 30 January 2012 19:04
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Have you tried packaging your package.xml within your extension jar as
described here:
http://checkstyle.sourceforge.net/config.html#Packages
?

HTH, Lars


Am 29.01.2012 17:42, schrieb tymieniecki:

> package softquatrachecks;
>
> import com.puppycrawl.tools.checkstyle.api.Check;
> import com.puppycrawl.tools.checkstyle.api.DetailAST;
> import com.puppycrawl.tools.checkstyle.api.FullIdent;
> import com.puppycrawl.tools.checkstyle.api.TokenTypes;
> import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
>
> /**
>   *
>   *
>   * This package provides the custom checks that were required outside
>   * of the standard checks provided
>   *
>   */
> public class LoggerAttrCheck extends Check {
> /**
>       *
>       * Indicator 7: Logging Mechanisms
>       *
>       * The Logger must be declared as a static final class attribute
>       *
>       */
>      @Override
>      public int[] getDefaultTokens()
>      {
>          return new int[] {
>              TokenTypes.VARIABLE_DEF
>          };
>      }
>
>      @Override
>      public void visitToken(DetailAST aAST)
>      {
>
>       if(aAST.getType()==TokenTypes.VARIABLE_DEF)
>           visitVariableDef(aAST);
>
>      }
>      /**
>       * Checks type of given variable.
>       * @param aAST variable to check.
>       */
>      private void visitVariableDef(DetailAST aAST)
>      {
>          checkVariableDefn(aAST);
>      }
>
>      /**
>       *
>       * Checks variable to see if its a Logger and static final
>       *      * @param aAST node to check.
>       */
>      private void checkVariableDefn(DetailAST aAST)
>      {
>          final DetailAST type = aAST.findFirstToken(TokenTypes.TYPE);
>          final FullIdent ident = CheckUtils.createFullType(type);
>          if ((ident.getText().equals("Logger"))) {
>
>
if((!aAST.branchContains(TokenTypes.FINAL))||(!aAST.branchContains(TokenType
s.LITERAL_STATIC)))
> {
>     log(type.getLineNo(), type.getColumnNo(),
>              "Logger not defined as static final class
attribute",

> type.getText());
> }
>          }
>      }
>
> }
> When the rule is processed I get the message:
> "Unable to create Checker: cannot initialize module TreeWalker -
> Unable to instantiate LoggerAttr"
>
> Now my checkstyle_packages.xml file in che checkstyle-5.5 folder is  :
> <?xml version="1.0" encoding="UTF-8"?>
>
>      <!DOCTYPE checkstyle-packages PUBLIC
>      &quot;-//Puppy Crawl//DTD Package Names 1.0//EN&quot;
>      &quot;http://www.puppycrawl.com/dtds/packages_1_0.dtd&quot;>
>
> <checkstyle-packages>
>    <package name="softquatrachecks"/>
> </checkstyle-packages>
>
> Any Ideas folks
>
>
> --
> View this message in context:
> http://checkstyle.2069334.n4.nabble.com/Checkstyle-Custom-rule-fails-t
> o-instantiate-tp4338632p4338632.html
> Sent from the CheckStyle - User mailing list archive at Nabble.com.
>
> ----------------------------------------------------------------------
> -------- Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft
> developers is just $99.99! Visual Studio, SharePoint, SQL - plus
> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when
> you
subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>


----------------------------------------------------------------------------
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


----------------------------------------------------------------------------
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

Lars Ködderitzsch
Hi again,

packaging the dtd is not necessary, and there are also no other xml
files to take care of.

Only thing that would come to mind to re-check, is whether your
extension jar is on Checkstyle's execution classpath.
Depending on your means of invoking Checkstyle (command line, ant,
maven, eclipse-cs plugin...) this may vary...

BR,
Lars

Am 31.01.2012 10:57, schrieb Mark Tymieniecki:

> Hi Lars,
>
> I have indeed packaged my check as described even trying both dtd1.0 and
> dtd1.3 so as to match the main rules xml file.
> Is there any other XML file that may need 'modifying' ?
>
> REgards
>
> -----Original Message-----
> From: Mark Tymieniecki [mailto:[hidden email]]
> Sent: 30 January 2012 20:30
> To: [hidden email]
> Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate
>
> Hi Lars,
>
> Sadly yes, but I will double check to ensure it is in the root path
>
> -----Original Message-----
> From: Lars Ködderitzsch [mailto:[hidden email]]
> Sent: 30 January 2012 19:04
> To: [hidden email]
> Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate
>
> Have you tried packaging your package.xml within your extension jar as
> described here:
> http://checkstyle.sourceforge.net/config.html#Packages
> ?
>
> HTH, Lars
>
>
> Am 29.01.2012 17:42, schrieb tymieniecki:
>> package softquatrachecks;
>>
>> import com.puppycrawl.tools.checkstyle.api.Check;
>> import com.puppycrawl.tools.checkstyle.api.DetailAST;
>> import com.puppycrawl.tools.checkstyle.api.FullIdent;
>> import com.puppycrawl.tools.checkstyle.api.TokenTypes;
>> import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
>>
>> /**
>>    *
>>    *
>>    * This package provides the custom checks that were required outside
>>    * of the standard checks provided
>>    *
>>    */
>> public class LoggerAttrCheck extends Check {
>> /**
>>        *
>>        * Indicator 7: Logging Mechanisms
>>        *
>>        * The Logger must be declared as a static final class attribute
>>        *
>>        */
>>       @Override
>>       public int[] getDefaultTokens()
>>       {
>>           return new int[] {
>>               TokenTypes.VARIABLE_DEF
>>           };
>>       }
>>
>>       @Override
>>       public void visitToken(DetailAST aAST)
>>       {
>>
>>       if(aAST.getType()==TokenTypes.VARIABLE_DEF)
>>           visitVariableDef(aAST);
>>
>>       }
>>       /**
>>        * Checks type of given variable.
>>        * @param aAST variable to check.
>>        */
>>       private void visitVariableDef(DetailAST aAST)
>>       {
>>           checkVariableDefn(aAST);
>>       }
>>
>>       /**
>>        *
>>        * Checks variable to see if its a Logger and static final
>>        *      * @param aAST node to check.
>>        */
>>       private void checkVariableDefn(DetailAST aAST)
>>       {
>>           final DetailAST type = aAST.findFirstToken(TokenTypes.TYPE);
>>           final FullIdent ident = CheckUtils.createFullType(type);
>>           if ((ident.getText().equals("Logger"))) {
>>
>>
> if((!aAST.branchContains(TokenTypes.FINAL))||(!aAST.branchContains(TokenType
> s.LITERAL_STATIC)))
>> {
>>       log(type.getLineNo(), type.getColumnNo(),
>>                "Logger not defined as static final class
> attribute",
>> type.getText());
>> }
>>           }
>>       }
>>
>> }
>> When the rule is processed I get the message:
>> "Unable to create Checker: cannot initialize module TreeWalker -
>> Unable to instantiate LoggerAttr"
>>
>> Now my checkstyle_packages.xml file in che checkstyle-5.5 folder is  :
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>>       <!DOCTYPE checkstyle-packages PUBLIC
>>       &quot;-//Puppy Crawl//DTD Package Names 1.0//EN&quot;
>>       &quot;http://www.puppycrawl.com/dtds/packages_1_0.dtd&quot;>
>>
>> <checkstyle-packages>
>>     <package name="softquatrachecks"/>
>> </checkstyle-packages>
>>
>> Any Ideas folks
>>
>>
>> --
>> View this message in context:
>> http://checkstyle.2069334.n4.nabble.com/Checkstyle-Custom-rule-fails-t
>> o-instantiate-tp4338632p4338632.html
>> Sent from the CheckStyle - User mailing list archive at Nabble.com.
>>
>> ----------------------------------------------------------------------
>> -------- Try before you buy = See our experts in action!
>> The most comprehensive online learning library for Microsoft
>> developers is just $99.99! Visual Studio, SharePoint, SQL - plus
>> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when
>> you
> subscribe now!
>> http://p.sf.net/sfu/learndevnow-dev2
>> _______________________________________________
>> Checkstyle-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>>
>
> ----------------------------------------------------------------------------
> --
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers is
> just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
> Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>
>
> ----------------------------------------------------------------------------
> --
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers is
> just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
> Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

tymieniecki
Hi Lars,

Yes I had a thought about this as well so the extension jar is in the same
folder as checkstyle-5.5-all.jar and this is declared on CLASSPATH

Regards

-----Original Message-----
From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 31 January 2012 18:03
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Hi again,

packaging the dtd is not necessary, and there are also no other xml files to
take care of.

Only thing that would come to mind to re-check, is whether your extension
jar is on Checkstyle's execution classpath.
Depending on your means of invoking Checkstyle (command line, ant, maven,
eclipse-cs plugin...) this may vary...

BR,
Lars

Am 31.01.2012 10:57, schrieb Mark Tymieniecki:

> Hi Lars,
>
> I have indeed packaged my check as described even trying both dtd1.0
> and
> dtd1.3 so as to match the main rules xml file.
> Is there any other XML file that may need 'modifying' ?
>
> REgards
>
> -----Original Message-----
> From: Mark Tymieniecki [mailto:[hidden email]]
> Sent: 30 January 2012 20:30
> To: [hidden email]
> Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to
> instantiate
>
> Hi Lars,
>
> Sadly yes, but I will double check to ensure it is in the root path
>
> -----Original Message-----
> From: Lars Ködderitzsch [mailto:[hidden email]]
> Sent: 30 January 2012 19:04
> To: [hidden email]
> Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to
> instantiate
>
> Have you tried packaging your package.xml within your extension jar as
> described here:
> http://checkstyle.sourceforge.net/config.html#Packages
> ?
>
> HTH, Lars
>
>
> Am 29.01.2012 17:42, schrieb tymieniecki:
>> package softquatrachecks;
>>
>> import com.puppycrawl.tools.checkstyle.api.Check;
>> import com.puppycrawl.tools.checkstyle.api.DetailAST;
>> import com.puppycrawl.tools.checkstyle.api.FullIdent;
>> import com.puppycrawl.tools.checkstyle.api.TokenTypes;
>> import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
>>
>> /**
>>    *
>>    *
>>    * This package provides the custom checks that were required outside
>>    * of the standard checks provided
>>    *
>>    */
>> public class LoggerAttrCheck extends Check {
>> /**
>>        *
>>        * Indicator 7: Logging Mechanisms
>>        *
>>        * The Logger must be declared as a static final class attribute
>>        *
>>        */
>>       @Override
>>       public int[] getDefaultTokens()
>>       {
>>           return new int[] {
>>               TokenTypes.VARIABLE_DEF
>>           };
>>       }
>>
>>       @Override
>>       public void visitToken(DetailAST aAST)
>>       {
>>
>>       if(aAST.getType()==TokenTypes.VARIABLE_DEF)
>>           visitVariableDef(aAST);
>>
>>       }
>>       /**
>>        * Checks type of given variable.
>>        * @param aAST variable to check.
>>        */
>>       private void visitVariableDef(DetailAST aAST)
>>       {
>>           checkVariableDefn(aAST);
>>       }
>>
>>       /**
>>        *
>>        * Checks variable to see if its a Logger and static final
>>        *      * @param aAST node to check.
>>        */
>>       private void checkVariableDefn(DetailAST aAST)
>>       {
>>           final DetailAST type = aAST.findFirstToken(TokenTypes.TYPE);
>>           final FullIdent ident = CheckUtils.createFullType(type);
>>           if ((ident.getText().equals("Logger"))) {
>>
>>
> if((!aAST.branchContains(TokenTypes.FINAL))||(!aAST.branchContains(Tok
> enType
> s.LITERAL_STATIC)))
>> {
>>       log(type.getLineNo(), type.getColumnNo(),
>>                "Logger not defined as static final class
> attribute",
>> type.getText());
>> }
>>           }
>>       }
>>
>> }
>> When the rule is processed I get the message:
>> "Unable to create Checker: cannot initialize module TreeWalker -
>> Unable to instantiate LoggerAttr"
>>
>> Now my checkstyle_packages.xml file in che checkstyle-5.5 folder is  :
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>>       <!DOCTYPE checkstyle-packages PUBLIC
>>       &quot;-//Puppy Crawl//DTD Package Names 1.0//EN&quot;
>>       &quot;http://www.puppycrawl.com/dtds/packages_1_0.dtd&quot;>
>>
>> <checkstyle-packages>
>>     <package name="softquatrachecks"/> </checkstyle-packages>
>>
>> Any Ideas folks
>>
>>
>> --
>> View this message in context:
>> http://checkstyle.2069334.n4.nabble.com/Checkstyle-Custom-rule-fails-
>> t
>> o-instantiate-tp4338632p4338632.html
>> Sent from the CheckStyle - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> -
>> -------- Try before you buy = See our experts in action!
>> The most comprehensive online learning library for Microsoft
>> developers is just $99.99! Visual Studio, SharePoint, SQL - plus
>> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when
>> you
> subscribe now!
>> http://p.sf.net/sfu/learndevnow-dev2
>> _______________________________________________
>> Checkstyle-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>>
>
> ----------------------------------------------------------------------
> ------
> --
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft
> developers is just $99.99! Visual Studio, SharePoint, SQL - plus
> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you
subscribe now!

> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>
>
> ----------------------------------------------------------------------
> ------
> --
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft
> developers is just $99.99! Visual Studio, SharePoint, SQL - plus
> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you
subscribe now!

> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>
>
> ----------------------------------------------------------------------
> -------- Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft
> developers is just $99.99! Visual Studio, SharePoint, SQL - plus
> HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you
subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>


----------------------------------------------------------------------------
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

Lars Ködderitzsch
Hello Mark,

if I got it right you need to fully specify each jar in the CLASSPATH
variable (or via -cp cmd line option) or use a classpath wildcard to
pick up all jars in a folder (e.g. foo/*).

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

HTH,
Lars

| Snipped for less scrolling



------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

tymieniecki
Hi Lars,

I am running Windows 7, and have set CLASSPATH correctly(trying both \ and /
in that path!), but cannot run directly from another folder so have to use
the -JAR option and then with the full path.
This is what it all end up looking like:

C:\02-Client-Code\Client\Checkstyle>java -D64 -jar
c:/checkstyle-5.5/checkstyle-5.5-all.jar -c
"C:/02-Client-Code/Client/Checkstyle/client_checks.xml" -f
 xml -o C:/02-Client-Code/Client/Checkstyle/Client_checkstyle_errors.xml -r
"E:/Eclipse Projects/Client_Rules_Test/src"
Unable to create Checker: cannot initialize module TreeWalker - Unable to
instantiate LoggerAttr
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize
module TreeWalker - Unable to instantiate LoggerAttr
        at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:178)
        at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(Automatic
Bean.java:184)
        at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:143)
        at com.puppycrawl.tools.checkstyle.Main.main(Main.java:120)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttr
        at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:155)
        at
com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:161)
        at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.ja
va:184)
        at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:157)        
... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttrCheck
        at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObj
ectFactory.java:98)
        at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:152)
        ... 6 more

This is very worrying as I have now tried it on three platforms and get the
same result each time.

Regards
-----Original Message-----
From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 01 February 2012 18:16
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Hello Mark,

if I got it right you need to fully specify each jar in the CLASSPATH
variable (or via -cp cmd line option) or use a classpath wildcard to pick up
all jars in a folder (e.g. foo/*).

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

HTH,
Lars

| Snipped for less scrolling



----------------------------------------------------------------------------
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

Oliver Burn
In the file "client_checks.xml" how is the "LoggerAttr" module defined? Try using the fully qualified class name.

On Thu, Feb 2, 2012 at 23:25, Mark Tymieniecki <[hidden email]> wrote:
Hi Lars,

I am running Windows 7, and have set CLASSPATH correctly(trying both \ and /
in that path!), but cannot run directly from another folder so have to use
the -JAR option and then with the full path.
This is what it all end up looking like:

C:\02-Client-Code\Client\Checkstyle>java -D64 -jar
c:/checkstyle-5.5/checkstyle-5.5-all.jar -c
"C:/02-Client-Code/Client/Checkstyle/client_checks.xml" -f
 xml -o C:/02-Client-Code/Client/Checkstyle/Client_checkstyle_errors.xml -r
"E:/Eclipse Projects/Client_Rules_Test/src"
Unable to create Checker: cannot initialize module TreeWalker - Unable to
instantiate LoggerAttr
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize
module TreeWalker - Unable to instantiate LoggerAttr
       at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:178)
       at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(Automatic
Bean.java:184)
       at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:143)
       at com.puppycrawl.tools.checkstyle.Main.main(Main.java:120)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttr
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:155)
       at
com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:161)
       at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.ja
va:184)
       at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:157)
... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttrCheck
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObj
ectFactory.java:98)
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:152)
       ... 6 more

This is very worrying as I have now tried it on three platforms and get the
same result each time.

Regards
-----Original Message-----
From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 01 February 2012 18:16
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Hello Mark,

if I got it right you need to fully specify each jar in the CLASSPATH
variable (or via -cp cmd line option) or use a classpath wildcard to pick up
all jars in a folder (e.g. foo/*).

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

HTH,
Lars

| Snipped for less scrolling



----------------------------------------------------------------------------
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

tymieniecki

Hi Oliver,

 

Many thanks for that, it ran slower so was obviously trying something but still with the same result. I amdefinitely doing something blindingly obvious and probably very stupid, but for the life of me cannot fathom what !

Regards

 

From: Oliver Burn [mailto:[hidden email]]
Sent: 02 February 2012 20:05
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

 

In the file "client_checks.xml" how is the "LoggerAttr" module defined? Try using the fully qualified class name.

On Thu, Feb 2, 2012 at 23:25, Mark Tymieniecki <[hidden email]> wrote:

Hi Lars,

I am running Windows 7, and have set CLASSPATH correctly(trying both \ and /
in that path!), but cannot run directly from another folder so have to use
the -JAR option and then with the full path.
This is what it all end up looking like:

C:\02-Client-Code\Client\Checkstyle>java -D64 -jar
c:/checkstyle-5.5/checkstyle-5.5-all.jar -c
"C:/02-Client-Code/Client/Checkstyle/client_checks.xml" -f
 xml -o C:/02-Client-Code/Client/Checkstyle/Client_checkstyle_errors.xml -r
"E:/Eclipse Projects/Client_Rules_Test/src"
Unable to create Checker: cannot initialize module TreeWalker - Unable to
instantiate LoggerAttr
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize
module TreeWalker - Unable to instantiate LoggerAttr
       at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:178)
       at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(Automatic
Bean.java:184)
       at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:143)
       at com.puppycrawl.tools.checkstyle.Main.main(Main.java:120)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttr
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:155)
       at
com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:161)
       at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.ja
va:184)
       at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:157)
... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttrCheck
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObj
ectFactory.java:98)
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:152)
       ... 6 more

This is very worrying as I have now tried it on three platforms and get the
same result each time.

Regards
-----Original Message-----
From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 01 February 2012 18:16
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Hello Mark,

if I got it right you need to fully specify each jar in the CLASSPATH
variable (or via -cp cmd line option) or use a classpath wildcard to pick up
all jars in a folder (e.g. foo/*).

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

HTH,
Lars

| Snipped for less scrolling



----------------------------------------------------------------------------
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user

 


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

Lars Ködderitzsch
Hello Mark,

what is the root cause of the exception you're receiving? NoClassDefFound? Or something other?

In case of NoClassDefFound you're probably having classpath issues (try the -cp parameter passed to the java executable ISO the CLASSPATH system variable).
In case of a different error there could be something wrong with your check class itself, e.g. missing public default constructor or something like that.
The root cause exception should usually reveal it...

BR,
Lars


Am 03.02.2012 18:25, schrieb Mark Tymieniecki:

Hi Oliver,

 

Many thanks for that, it ran slower so was obviously trying something but still with the same result. I amdefinitely doing something blindingly obvious and probably very stupid, but for the life of me cannot fathom what !

Regards

 

From: Oliver Burn [[hidden email]]
Sent: 02 February 2012 20:05
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

 

In the file "client_checks.xml" how is the "LoggerAttr" module defined? Try using the fully qualified class name.

On Thu, Feb 2, 2012 at 23:25, Mark Tymieniecki <[hidden email]> wrote:

Hi Lars,

I am running Windows 7, and have set CLASSPATH correctly(trying both \ and /
in that path!), but cannot run directly from another folder so have to use
the -JAR option and then with the full path.
This is what it all end up looking like:

C:\02-Client-Code\Client\Checkstyle>java -D64 -jar
c:/checkstyle-5.5/checkstyle-5.5-all.jar -c
"C:/02-Client-Code/Client/Checkstyle/client_checks.xml" -f
 xml -o C:/02-Client-Code/Client/Checkstyle/Client_checkstyle_errors.xml -r
"E:/Eclipse Projects/Client_Rules_Test/src"
Unable to create Checker: cannot initialize module TreeWalker - Unable to
instantiate LoggerAttr
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize
module TreeWalker - Unable to instantiate LoggerAttr
       at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:178)
       at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(Automatic
Bean.java:184)
       at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:143)
       at com.puppycrawl.tools.checkstyle.Main.main(Main.java:120)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttr
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:155)
       at
com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:161)
       at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.ja
va:184)
       at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:157)
... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttrCheck
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObj
ectFactory.java:98)
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:152)
       ... 6 more

This is very worrying as I have now tried it on three platforms and get the
same result each time.

Regards
-----Original Message-----
From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 01 February 2012 18:16
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Hello Mark,

if I got it right you need to fully specify each jar in the CLASSPATH
variable (or via -cp cmd line option) or use a classpath wildcard to pick up
all jars in a folder (e.g. foo/*).

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

HTH,
Lars

| Snipped for less scrolling



----------------------------------------------------------------------------
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user

 



------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2


_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: Checkstyle Custom rule fails to instantiate

tymieniecki

HI Lars,

 

Ok so I checked and rechecked spelling in CLASSPATH and –cp and then the class itself which you have seen. I have checked file permissions etc. I even cut down my config file to :

 

<?xml version="1.0"?>

<!DOCTYPE module PUBLIC

          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"

          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">

    <module name="TreeWalker">

            <property name="fileExtensions" value="java"/>          

                    

            <!-- Check for Logger defined as static Final  -->

            <!-- Q23                                       -->

        <module name="com.sisclear.checkstyle.LoggerAttrCheck">

                 <property name="severity" value="error"/>

            </module>

    </module>

</module>

 

I inserted a default constructor even though the example in the manual does not seem to have one, but something is very wrong here. I create a jar file named com.sisclear.checkstyle.jar from within Eclipse, with the checkstyle-packages.xml in the root whilst the source is built from checkstyle_checks.src.com.sisclear.checkstyle. I use jre7 as this is my system default. Finding the root cause is somewhat laughable as the error messages point to a mismatch between what I am providing and what is there.

 

Do you have any sample custom checks(not in manual) with ALL their files I could look at, there must be a pattern I am missing.

Regards

 

Mark

 

 

From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 03 February 2012 18:05
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

 

Hello Mark,

what is the root cause of the exception you're receiving? NoClassDefFound? Or something other?

In case of NoClassDefFound you're probably having classpath issues (try the -cp parameter passed to the java executable ISO the CLASSPATH system variable).
In case of a different error there could be something wrong with your check class itself, e.g. missing public default constructor or something like that.
The root cause exception should usually reveal it...

BR,
Lars


Am 03.02.2012 18:25, schrieb Mark Tymieniecki:

Hi Oliver,

 

Many thanks for that, it ran slower so was obviously trying something but still with the same result. I amdefinitely doing something blindingly obvious and probably very stupid, but for the life of me cannot fathom what !

Regards

 

From: Oliver Burn [[hidden email]]
Sent: 02 February 2012 20:05
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

 

In the file "client_checks.xml" how is the "LoggerAttr" module defined? Try using the fully qualified class name.

On Thu, Feb 2, 2012 at 23:25, Mark Tymieniecki <[hidden email]> wrote:

Hi Lars,

I am running Windows 7, and have set CLASSPATH correctly(trying both \ and /
in that path!), but cannot run directly from another folder so have to use
the -JAR option and then with the full path.
This is what it all end up looking like:

C:\02-Client-Code\Client\Checkstyle>java -D64 -jar
c:/checkstyle-5.5/checkstyle-5.5-all.jar -c
"C:/02-Client-Code/Client/Checkstyle/client_checks.xml" -f
 xml -o C:/02-Client-Code/Client/Checkstyle/Client_checkstyle_errors.xml -r
"E:/Eclipse Projects/Client_Rules_Test/src"
Unable to create Checker: cannot initialize module TreeWalker - Unable to
instantiate LoggerAttr
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize
module TreeWalker - Unable to instantiate LoggerAttr
       at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:178)
       at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(Automatic
Bean.java:184)
       at com.puppycrawl.tools.checkstyle.Main.createChecker(Main.java:143)
       at com.puppycrawl.tools.checkstyle.Main.main(Main.java:120)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttr
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:155)
       at
com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:161)
       at
com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.ja
va:184)
       at
com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:157)
... 3 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable
to instantiate LoggerAttrCheck
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.doMakeObject(PackageObj
ectFactory.java:98)
       at
com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObj
ectFactory.java:152)
       ... 6 more

This is very worrying as I have now tried it on three platforms and get the
same result each time.

Regards
-----Original Message-----
From: Lars Ködderitzsch [mailto:[hidden email]]
Sent: 01 February 2012 18:16
To: [hidden email]
Subject: Re: [Checkstyle-user] Checkstyle Custom rule fails to instantiate

Hello Mark,

if I got it right you need to fully specify each jar in the CLASSPATH
variable (or via -cp cmd line option) or use a classpath wildcard to pick up
all jars in a folder (e.g. foo/*).

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

HTH,
Lars

| Snipped for less scrolling



----------------------------------------------------------------------------
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers is
just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro
Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user

 




------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2




_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user

 


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user