An extensible multilanguage static code analyzer.

Overview

PMD

Join the chat at https://gitter.im/pmd/pmd Build Status Maven Central Reproducible Builds Coverage Status Codacy Badge Contributor Covenant

About

PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. It supports Java, JavaScript, Salesforce.com Apex and Visualforce, Modelica, PLSQL, Apache Velocity, XML, XSL, Scala.

Additionally it includes CPD, the copy-paste-detector. CPD finds duplicated code in C/C++, C#, Dart, Fortran, Go, Groovy, Java, JavaScript, JSP, Kotlin, Lua, Matlab, Modelica, Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift, Visualforce and XML.

Support

Source

Our latest source of PMD can be found on GitHub. Fork us!

The rule designer is developed over at pmd/pmd-designer. Please see its README for developer documentation.

Website

More information can be found on our Website.

Issues
  • PMD-3546925	 PLSQL Language for PMD

    PMD-3546925 PLSQL Language for PMD

    Patch to:- add Oracle PL/SQL language to PMD languages add PL/SQL as an option to CPD

    AST is derived from PLDoc parser (pldoc.sourceforge.net) 1.3.2.

    The AST also covers a subset of SQL*Plus.

    opened by sturton 88
  • Call For Logo

    Call For Logo

    PMD’s logo was great for a long time. But now we want to take the opportunity with the next major release to change our logo in order to use a more “politically correct” one. As you probably know, PMD’s current logo is showing a gun with the tagline “Don’t shoot the messenger”. While this was probably intended as a joke when PMD was a minor tool 12 years back, it might be offensive nowadays / not aligned with corporate policies from organizations that would otherwise benefit from PMD. PMD is in no way glorifying weapons or violence - PMD is about software quality, and helping developers improve their craft. Having a logo that illustrates those values without negative connotations makes it possible to use the logo in presentations without warning audiences.

    Now comes your part: If you have a good idea for a logo, please share it with us! Maybe you like to design logos or you are even a professional designer, then that’s your chance :smile:

    This issue here is used to collect the suggestions and let all of you vote. Each suggested logo has its own comment, and everybody can vote for a logo with a “thumbs up” (:+1:). The votes are open until the end of May 2019. The logo, that has the most votes will win.

    Note: If you submit a logo, you must hold the rights for the logo and be willing to concede such rights to the PMD project free of charge upon being selected.

    opened by adangel 39
  • [core] Allow XML dumps of ASTs

    [core] Allow XML dumps of ASTs

    Checkstyle provides a command-line option that displays the AST tree for a single file. I know this can be done through the Rule Designer. Is there a possibility that PMD will allow for the AST tree to be output via the CLI? Better still, output the AST as an xml doc?

    I assume the Xpath works on elements specified in the grammar. It would be easier to work with an xml document that mimics the tree structure so that the Xpath can be tested independently and then integrated into rule changes, if needed. JavaParser allows for xml to be output for a Java source.

    We could add an "export to XML" option in the designer. We could even let this XML document be dumpable from the designer CLI, without starting the GUI. But I don't think the value added to adding this to the PMD CLI would justify the added complexity.

    opened by oowekyala 33
  • [java] imports/UnusedImport rule not considering static inner classes of imports

    [java] imports/UnusedImport rule not considering static inner classes of imports

    Rule Set: java-imports/UnusedImports

    Code Sample demonstrating the issue:

    import com.supercilex.robotscouter.util.IoHelper;
    
    public class Foo {
        /** {@link SpreadsheetExporter#writeAndShareTeams(Fragment, IoHelper.RequestHandler, List)} */ This should be considered an import
        public void foo() {}
    }
    

    Running PMD through: Gradle

    a:bug has:pr 
    opened by SUPERCILEX 32
  • [java] Ignore unused declarations that have special name

    [java] Ignore unused declarations that have special name

    Implemented solution via #3066:

    The following rules are affected:

    The following variable names are ignored:

    • any name starting with ignored, e.g. ignoredParameter
    • any name starting with unused, e.g. unusedVar

    Is your feature request related to a problem? Please describe. UnusedLocalVariable, UnusedFormalParameter flag all unused variables.

    Describe the solution you'd like Please add a property to the rule specifying a pattern such as starts with $, _ or unused for the variable name so that variables that meet the criteria are excluded. Additionally, you could support custom annotations that mark the variables as Unused. e.g., @Unused or @Ignored. E.g., https://github.com/Lanchon/r8/blob/e22a77d26e30615bfc9b5f598bb0f58f10dd082c/src/test/java/com/android/tools/r8/shaking/ifrule/IfOnAnnotationTestClasses.java

    Describe alternatives you've considered Example code flagged by ForLoopCanBeForEach when usual for loop used:

    @SuppressWarnings("PMD.UnusedLocalVariable")
      @Override
      public Solution solve() {
        int[] dp = new int[capacity + 1];
    
        List<Item> itemsList = new ArrayList<>(items.length);
        int i = 0;
        for (int dpVal : dp) {
          for (Item item : items) {
            if (item.weight <= i) {
              int includedVal = dp[i - item.weight] + item.value;
              if (includedVal > dp[i]) dp[i] = includedVal;
            }
          }
          ++i;
        }
        path(items, capacity, dp, itemsList);
        itemsList = Item.pack(itemsList);
        return new Solution(itemsList, dp[capacity]);
      }
    

    Additional context Haskell/Python style Error-prone

    Also see #2923

    Referenced from: https://github.com/pmd/pmd/issues/2838

    an:enhancement 
    opened by Fernal73 29
  • SourceForge: Role and purpose

    SourceForge: Role and purpose

    Description:

    Can anyone tell me what role and purpose does SourceForge continue to serve PMD as?

    I signed up at the group and apart from an update email from Oracle wrt to upcoming Java releases, there is no activity on the group discussions.

    As far as I can see, this list is defunct. If it's being used, it's mainly as an referenced archive and a mailing list.

    You can easily create a Google group, one for PMD developers and another for users to answer more general questions.

    Existing users can be migrated to these groups with their permission.

    There appears to be some commit activity visible for pmd-core.

    https://sourceforge.net/projects/pmd/

    Additionally, the site is not mobile-friendly either.

    a:question 
    opened by Fernal73 27
  • Apex_CustomRule: Check existence of specific class / method name using count function

    Apex_CustomRule: Check existence of specific class / method name using count function

    I'm writing customrule to verify an ApexTestClass has specific class (with specific name e.g. "bulkApexTest") implemented. To achieve this, I'm planning the following

    Check the ApexTestClass not having class with name = 'bulkApexTest'. To do this, I was trying using count function (//UserClass[count(/UserClassMethods[@Image="bulkApexTest"])=0]. But this expression is not returning the expected results. please find the sample code below.

    /*************************************************************************************************** Class Name: AddSite_CX ****************************************************************************************************/

    public class AddSite_CX {
    public Site_Contacts__c siteContactObj {get; set;} Public Case caseRecord {get; Set;} Public String contactId {get; set;} Public String siteContactRecordTypeId {get; set;} Public String locIdString {get; set;} Public String locIAddressString {get; set;} Public String siteSFId {get; set;} Public Boolean showSaveButton{get; set;} Public String noValue{get; set;} Public Boolean throwError {get; Set;} Public Boolean hasrecords {get; set;} Public Boolean showAdvSearchComponent {get; set;} Public String caseId {get; set;} Public String newSiteId {get; set;} Public Set setRelatedSites {get; set;} Public Map<String, Id> mapOfSiteRecordTypeNamesAndId {get; set;} Public AddressSearch_CX.addressWrapper unStructuredAddress {get; set;}

    public AddSite_CX(ApexPages.StandardController sController){          
        throwError = False;
        caseRecord = new Case();
        caseRecord = (Case)sController.getRecord();
        if (caseRecord!=null)
        {
            caseRecord = [select id, status, casenumber,site__c from case where id=:caseRecord.Id];
            caseId = caseRecord.Id;
        } 
        
        if(caseRecord.status=='Closed')
        {
            throwError = True;
            ApexPages.Message PageErrorMessage = new ApexPages.Message(ApexPages.Severity.ERROR,HelperUtility.getErrorMessage('032'));
            ApexPages.addMessage(PageErrorMessage);
        }  
    }
    
    public AddSite_CX(ApexPages.StandardSetController controller) {  
       showSaveButton = False;
       throwError = False;
       showAdvSearchComponent = False;
       contactId  = ApexPages.currentPage().getParameters().get('id');
       // Get the RecordType Id of SiteContact by passing the RecordType Name - Default RecordType is 'Customer Service' 
       // Using CustomLabel: DefaultSiteContactRecordType - Customer Service
       Id siteContactRecordTypeId = Schema.SObjectType.Site_Contacts__c.getRecordTypeInfosByName().get(Label.DefaultSiteContactRecordType).getRecordTypeId();
       siteContactObj = new Site_Contacts__c(RecordTypeID=siteContactRecordTypeId, Related_Contact__c=contactId);
       // Prepare map of Site Record Type and its corresponding ID
       mapOfSiteRecordTypeNamesAndId = new Map<String, Id>();
       mapOfSiteRecordTypeNamesAndId = HelperUtility.pullAllRecordTypes('site__c');
       // Prepare a set of RelatedSite ids
       setRelatedSites = new Set<String>(); 
       for(Site_Contacts__c c: [select id,Related_Contact__c,Related_Site__c from Site_Contacts__c where Related_Contact__c =: contactId])
           setRelatedSites.add(c.Related_Site__c);
           
       system.debug('***setRelatedSites*'+setRelatedSites);    
       system.debug('***mapofCaseRecordTypeNameandId*'+mapOfSiteRecordTypeNamesAndId );
    } 
    
    public pagereference saveSiteContact()
    {        
        pagereference p;
         List<Site__c> s = new List<Site__c>();
        // Site is available in SF map that ID to the related Site
        // If the Searched Site is already Associated to the Contact throw error message.
        // If Site is not available in SF create a new Unverified Site and map that ID to the related site.
        
        system.debug('****siteSFId'+siteSFId);
        if(siteSFId!=null && siteSFId!='')
        {
           If(setRelatedSites.size()>0)
              checkAssociatedSite(setRelatedSites, siteSFId);
           else
              siteContactObj.Related_Site__c = siteSFId;  
        }
        else
        {            
            Site__c newUnverifiedSite = new Site__c();
            if(HelperUtility.checkNullValue(locIdString))
               s = [select id, Location_Id__c from Site__c where Location_Id__c=: locIdString];            
           try{
                If(HelperUtility.checkNullValue(locIAddressString))
                {
                    // If a Site is available with the Location Id
                    if(s.size()>0)
                      newUnverifiedSite = s[0];                   
                    else
                    { 
                         newUnverifiedSite.RecordTypeID= (HelperUtility.checkNullValue(locIdString))? mapOfSiteRecordTypeNamesAndId.get('Verified') : mapOfSiteRecordTypeNamesAndId.get('Unverified');                       
                         newUnverifiedSite.Site_Address__c= 'locIAddressString';
                         newUnverifiedSite.Location_Id__c=locIdString;
                         newUnverifiedSite.Name = locIAddressString;                                                               
                    }
    
                    // perform ServiceQualification from External System.                   
                    newUnverifiedSite = HelperUtility.executeServiceQualification(newUnverifiedSite, newUnverifiedSite.Location_Id__c);   
                    System.debug('*** newUnverifiedSite ==>'+ newUnverifiedSite);
                    Upsert newUnverifiedSite; 
    
                    // Check If the site is already Associated with Contact or not                     
                   If(setRelatedSites.size()>0)
                      checkAssociatedSite(setRelatedSites, string.valueof(newUnverifiedSite.id));                       
                    else
                      siteContactObj.Related_Site__c=newUnverifiedSite.id;  
                }
                else
                {
                    throwError = True;
                    ApexPages.Message PageErrorMessage = new ApexPages.Message(ApexPages.Severity.ERROR,HelperUtility.getErrorMessage('005'));
                    ApexPages.addMessage(PageErrorMessage);
                }
            }
            catch(exception ex)
            {
               apexpages.addmessages(ex);
            }
        }
        // Insert SiteContact once we have associated Site.
        if(siteContactObj.Related_Site__c!=null)
        {
            insert siteContactObj;
            p = new PageReference('/'+siteContactObj.id);
            p.setRedirect(true);
        }
        else {
            p=null;
            showSaveButton = True;
        }                
        return p; 
    }
    
     public class sWrapper{
        public string technologyType { get; set; }
        public integer serviceClass { get; set; }
        public string rolloutType { get; set; }
    }
    
    public void getaddressDetails()
    {
        system.debug('*** siteSFId ==>'+ siteSFId );
        system.debug('*** locIdString ==>'+ locIdString);
        system.debug('*** locIAddressString ==>'+ locIAddressString); 
        if(HelperUtility.checkNullValue(siteSFId) || HelperUtility.checkNullValue(locIdString))
         hasrecords = True;
    }
    
    Public void flipAddressComponent(){
        showAdvSearchComponent = True;
    }
    
    Public void checkAssociatedSite(set<String> relatedSites, string relatedSiteId)
    {
        If(!relatedSites.contains(relatedSiteId))
            siteContactObj.Related_Site__c=relatedSiteId;
        else
        {
            throwError = True;
            ApexPages.Message PageErrorMessage = new ApexPages.Message(ApexPages.Severity.ERROR,HelperUtility.getErrorMessage('004'));
            ApexPages.addMessage(PageErrorMessage);
        }  
    
    }
    

    public pagereference updateCaseWithSiteInfo(){ system.debug('*** newSiteId ==>'+ newSiteId);
    case c= [select id,site__c,site__r.name from case where id=:caseId]; c.site__c = ID.valueof(newSiteId); update c;

       // Get all SiteContacts for the related site               
       set<string> setSiteContacts = new set<String>();
       if(newSiteId!=null)
       {
            for(Site_Contacts__c siteC : [Select id, Related_Contact__c, Related_Site__c, Role__c from Site_Contacts__c where Related_Site__c =: newSiteId])
            {
                setSiteContacts.add(siteC.Related_Contact__c);
            }
       }
       // Create siteContacts which are not already associated.
       List<Site_Contacts__c> lstSC = new List<Site_Contacts__c>();       
       for(Case_Contact__c cc: [Select id, Case__c, Case__r.Site__c, Contact__c, Role__c from Case_Contact__c where Case__c=:c.Id])
       {
          if(!setSiteContacts.Contains(string.valueof(cc.Contact__c)))
          {
                Site_Contacts__c sc = new Site_Contacts__c();
                sc.Related_Contact__c = cc.Contact__c;
                sc.Related_Site__c = cc.Case__r.Site__c;
                sc.Role__c = cc.Role__c ;
                lstSC.add(sc);
          }
        }
        // Insert SiteContacts.
        if(lstSC.size()>0)
         upsert lstSC;
        
        pagereference p;       
        p = new pagereference('/'+caseId);
        p.setRedirect(true);
        return p;
    }     
    
    @RemoteAction
    public static string getAddressSearchData(AddressSearch_CX.addressWrapper selectedAddress, string cId){
       site__c s = HelperUtility.instantiateUnStructuredVerifiedSite(selectedAddress);
       upsert s;      
       return string.valueof(s.id);
    }
    
     public class bulkApexTest
    {
        Public string technologyType
        public string serviceClass
        public string Isbulk
    
    newsArticles = [SELECT Id, KnowledgeArticleId FROM News__kav WHERE PublishStatus = 'Draft' AND Language = 'en_US' ORDER BY Title];
        for (News__kav article : newsArticles) 
        {
            KbManagement.PublishingService.publishArticle(article.KnowledgeArticleId, true);
            articleIds.add(article.Id);
        }
    }
    
    @RemoteAction
    public static AddressSearch_CX.addressWrapper createUnverifiedSite(AddressSearch_CX.StructuredAddress inputAddress){
        site__c siteRec = HelperUtility.instantiateStructuredUnVerifiedSite(inputAddress);
        insert siteRec;
        AddressSearch_CX.addressWrapper createdUnverifiedAddress = new AddressSearch_CX.addressWrapper ();
        List<Site__c> siteRecords = [SELECT Id, Name, Site_Address__c, Location_Id__c, Asset_Number__c FROM site__c WHERE Id =: siteRec.id LIMIT 1];
        createdUnverifiedAddress.address = siteRecords.get(0).Site_Address__c;
        createdUnverifiedAddress.locationId = siteRecords.get(0).Location_Id__c;
        createdUnverifiedAddress.addressFrom =  'UnVerified';
        createdUnverifiedAddress.assetNumber = siteRecords.get(0).Asset_Number__c;
        createdUnverifiedAddress.sfRecordId = siteRecords.get(0).Id;
        createdUnverifiedAddress.SiteSfRecordName = siteRecords.get(0).Name;
        return createdUnverifiedAddress;
    }
    
    a:question 
    opened by haigsn 24
  • [ui] XPath AutoComplete

    [ui] XPath AutoComplete

    So the feature is in very early stages as we discussed the basic rudimentary setup is there I have used a basic contains check to look out for the suggestions of XPath.

    Working on the UI that's a part I need help around @oowekyala
    maybe some guidelines.

    is:WIP 
    opened by akshatbahety 23
  • [apex] Make Rule suppression work

    [apex] Make Rule suppression work

    Before submitting a PR, please check that:

    • [x] The PR is submitted against master. The PMD team will merge back to support branches as needed.
    • [x] mvn test passes.
    • [x] mvn checkstyle:check passes. Check this for more info

    PR Description: Enables PMD-like rule suppression for the Apex language and by that implements https://github.com/pmd/pmd/issues/265.

    Not all suppression variations from Java could be ported due to the limitations of the current Apex parser to recognize undefined Annotation parameters.

    Those will work on classes, interfaces, member and method variables, methods and method parameters:

    • @SupressWarnings('PMD') to supress all Apex rules
    • @SupressWarnings('all') to supress all Apex rules
    • @SupressWarnings('PMD.ARuleName') to supress only the rule named ARuleName
    • @SupressWarnings('PMD.ARuleName, PMD.AnotherRuleName') to supress only the rule named ARuleName or AnotherRuleName
    an:enhancement 
    opened by rsoesemann 23
  • [apex] Add custom Codacy.com Time-to-Fix property to ruleset.xml

    [apex] Add custom Codacy.com Time-to-Fix property to ruleset.xml

    Before submitting a PR, please check that:

    • [x] The PR is submitted against master. The PMD team will merge back to support branches as needed.
    • [x] mvn test passes.
    • [x] mvn checkstyle:check passes. Check this for more info

    PR Description: PMD change to solve https://github.com/codacy/codacy-pmdjava/issues/29 where Codacy.com always showed 5min to fix for each PMD issue.

    opened by rsoesemann 23
  • [java] Fix NPE in `InefficientStringBuffering` with Records

    [java] Fix NPE in `InefficientStringBuffering` with Records

    Related issues

    • Fixes #3420

    Ready?

    • [x] Added unit tests for fixed bug/feature
    • [x] Passing all unit tests
    • [x] Complete build ./mvnw clean verify passes (checked automatically by github actions)
    • [x] Added (in-code) documentation (if needed)
    opened by adangel 1
  • [core] Stop printing CLI usage text when exiting due to invalid parameters

    [core] Stop printing CLI usage text when exiting due to invalid parameters

    Is your feature request related to a problem? Please describe. When making a mistake in CLI parameters a wall of text is printed and the actual error message is completely drowned out. Also this is a real problem with the -help option. Because of #3424, pmd --help is actually incorrect (pmd -help should be used instead). But since the usage text is printed, we have the impression that it actually worked, only to be disappointed that this wall of text doesn't mention the CLI syntax. It comes off as buggy and unhelpful.

    Describe the solution you'd like Just print the error message, followed by the line Run with --help to get more information or something like that. Note that --help doesn't exist yet (#3424)

    an:enhancement in:cli 
    opened by oowekyala 0
  • [core] Deprecate `-language` option

    [core] Deprecate `-language` option

    Is your feature request related to a problem? Please describe. The couple of CLI options -language and -version are used to specify the language version to use when discovering a file for that language. They're virtually not documented, only work when they're specified together (and otherwise just don't do anything, but that doesn't produce a warning), and are not repeatable. Ultimately we could just use a single option and make it repeatable.

    Describe the solution you'd like

    • Introduce a new option --use-version (as per #3424) which has arity 2 (language AND version number). It would be used like --use-version java 16.
    • Maybe make it repeatable if it's easy enough.
    • Deprecate -language and -version.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Relevant current issues:

    • #3424
    • #3425
    • #3417 introduces --force-language
    an:enhancement in:cli 
    opened by oowekyala 0
  • [core] Add a `--version` CLI option

    [core] Add a `--version` CLI option

    Is your feature request related to a problem? Please describe. PMD doesn't have a --version option to print its own version. This is contrary to the GNU standards, which makes the CLI harder to approach, esp. since -version exists and means something else.

    Describe the solution you'd like Add a --version option to PMD's CLI. This would print the version and exit. This would play well with #3424.

    Additional context #3424 warns against updating -version to --version, to leave room for this feature request.

    an:enhancement in:cli 
    opened by oowekyala 0
  • [core] Migrate CLI to using GNU-style long options

    [core] Migrate CLI to using GNU-style long options

    Is your feature request related to a problem? Please describe. Currently our CLI uses ugly BSD-style options (long options with a single dash). Using a double dash for long options is more usual in modern programs (this is "GNU style"). Also our names are inconsistent,

    • eg -failOnViolation also has the variant --failOnViolation as synonym, but it's the only option that does
    • eg we use inconsistent word splitting conventions throughout, eg failOnViolation is camel case, -norulesetcompatibility is "clump-together case" as far as I'm concerned, while -no-cache is in the more usual style for long CLI options

    Describe the solution you'd like

    • Add long variants for all our CLI options that
      • are GNU style (--)
      • use a consistent casing convention, eg --fail-on-violation, --no-ruleset-compatibility
    • Output a deprecation warning when the old variants are used.
    • Remove the old variants in PMD 7

    Additional thoughts:

    • -version should NOT be renamed to --version. As per the gnu standards, the --version option should instead print the version of PMD. I suggest renaming it to --use-version.
    • CPD uses GNU style options and mostly uses --this-style but --failOnViolation is camel case and could also be updated
    • I'm not sure if we should rename --filelist to --file-list. It feels like a single word now with a specialized meaning, but I'm not sure that's the case
    an:enhancement in:cli 
    opened by oowekyala 1
  • [java] Error processing identifiers with Unicode

    [java] Error processing identifiers with Unicode

    Affects PMD Version:

    6.36.0

    Description:

    PMD fails to analyze Java source with variables named with Unicode characters. Additionally, I think this is causing Eclipse to entirely crash when this is encountered (as opposed to failing more gracefully) while using the com.basistech.m2e.code.quality.pmd plugin but I'm not certain how to diagnose this specifically.

    This is likely related to the following issues but I created this issues for Java specifically and to mention the Eclipse crash:

    • #2752
    • #2605
    • #2604
    • #1757

    Exception Stacktrace:

    net.sourceforge.pmd.PMDException: Error while processing /home/nidoyle/Work/Source/PmdTest/src/main/java/com/example/pmdtest/PmdTest.java
    	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:119)
    	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:95)
    	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:57)
    	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:85)
    	at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:29)
    	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    Caused by: net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error at line 5, column 28.  Encountered: "\u1d64" (7524), after : "" (in lexical state 0)
    	at net.sourceforge.pmd.lang.java.ast.JavaParserTokenManager.getNextToken(JavaParserTokenManager.java:2377)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.jj_scan_token(JavaParser.java:13219)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.jj_3R_126(JavaParser.java:9270)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.jj_3_13(JavaParser.java:9421)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.jj_2_13(JavaParser.java:7931)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBodyDeclaration(JavaParser.java:1782)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBody(JavaParser.java:1738)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceDeclaration(JavaParser.java:879)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.TypeDeclaration(JavaParser.java:781)
    	at net.sourceforge.pmd.lang.java.ast.JavaParser.CompilationUnit(JavaParser.java:501)
    	at net.sourceforge.pmd.lang.java.AbstractJavaParser.parse(AbstractJavaParser.java:62)
    	at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:127)
    	at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:191)
    	at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:113)
    	... 10 more
    

    Code Sample demonstrating the issue:

    package com.example.pmdtest;
    
    public class PmdTest {
    
    	private static final int lᵤ = 1;
    	private static final int μᵤ = 2;
    
    	public static void main(String[] args) {
    		System.out.println(lᵤ + μᵤ);
    	}
    
    }
    

    Steps to reproduce:

    Please provide detailed steps for how we can reproduce the bug.

    1. mvn clean verify

    Running PMD through: [Maven]

    a:bug 
    opened by njdoyle 0
  • [java] NPE in `InefficientStringBuffering` with Records

    [java] NPE in `InefficientStringBuffering` with Records

    Affects PMD Version:

    6.36.0

    Description:

    I get an exception running PMD on Gradle 7.1.1 on JDK 16.

    Exception Stacktrace:

    Exception applying rule InefficientStringBuffering on file /home/boris/code/test/src/main/java/a/A.java, continuing with next rule
    java.lang.NullPointerException: Cannot invoke "net.sourceforge.pmd.lang.java.ast.AccessNode.isFinal()" because "accessNodeParent" is null
            at net.sourceforge.pmd.lang.java.rule.performance.InefficientStringBufferingRule.visit(InefficientStringBufferingRule.java:86)
            at net.sourceforge.pmd.lang.java.ast.ASTAdditiveExpression.jjtAccept(ASTAdditiveExpression.java:40)
            at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visitAll(AbstractJavaRule.java:163)
            at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply(AbstractJavaRule.java:157)
            at net.sourceforge.pmd.lang.internal.DefaultRulechainVisitor.visit(DefaultRulechainVisitor.java:26)
            at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:99)
            at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:72)
            at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:160)
            at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:200)
            at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:113)
            at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:95)
            at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:57)
            at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:85)
            at net.sourceforge.pmd.processor.MonoThreadProcessor.runAnalysis(MonoThreadProcessor.java:32)
            at net.sourceforge.pmd.processor.AbstractPMDProcessor.processFiles(AbstractPMDProcessor.java:139)
            at net.sourceforge.pmd.PMD.processFiles(PMD.java:359)
            at net.sourceforge.pmd.ant.internal.PMDTaskImpl.doTask(PMDTaskImpl.java:188)
            at net.sourceforge.pmd.ant.internal.PMDTaskImpl.execute(PMDTaskImpl.java:279)
            at net.sourceforge.pmd.ant.PMDTask.execute(PMDTask.java:50)
            at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
            at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.base/java.lang.reflect.Method.invoke(Method.java:567)
            at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
            at groovy.util.AntBuilder.performTask(AntBuilder.java:335)
            at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:280)
            at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:90)
            at jdk.internal.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
            at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.base/java.lang.reflect.Method.invoke(Method.java:567)
            at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
            at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
            at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:484)
            at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:196)
            at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:163)
            at org.gradle.api.internal.project.antbuilder.AntBuilderDelegate.nodeCompleted(AntBuilderDelegate.java:124)
            at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:160)
            at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:74)
            at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:44)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148)
            at org.gradle.api.plugins.quality.internal.PmdInvoker$_runPmd_closure1.doCall(PmdInvoker.groovy:119)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
            at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            ...
    

    Code Sample demonstrating the issue:

    build.gradle:

    plugins {
    	id 'java'
    	id 'pmd'
    }
    
    repositories {
    	mavenCentral()
    }
    
    dependencies {
    	pmd 'net.sourceforge.pmd:pmd-core:6.36.0'
    	pmd 'net.sourceforge.pmd:pmd-java:6.36.0'
    
    	implementation 'com.google.guava:guava:30.1.1-jre'
    }
    
    tasks.withType(Pmd).configureEach {
    	ruleSetFiles = files("${rootDir}/pmd.xml")
    }
    

    src/main/java/a/A.java:

    package a;
    
    import java.io.InputStream;
    
    import com.google.common.io.ByteStreams;
    
    public record A(long from, long to) {
    	public InputStream a() {
    		return ByteStreams.limit(null, to - from);
    	}
    }
    

    pmd.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <ruleset name="pmd"
             xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://raw.githubusercontent.com/pmd/pmd/master/pmd-core/src/main/resources/ruleset_2_0_0.xsd">
        <rule ref="category/java/performance.xml">
        </rule>
    </ruleset>
    

    Steps to reproduce:

    Run gradle pmdMain on the build.gradle file above.

    a:bug 
    opened by boris-petrov 0
  • [apex] ApexCRUDViolation not checking queries when used as map constructor arguments

    [apex] ApexCRUDViolation not checking queries when used as map constructor arguments

    Affects PMD Version: 5.5.3 - 6.36.0

    Rule:

    ApexCRUDViolation

    Description:

    When a query is issued inside a map constructor the CRUD check is not enforced

    Code Sample demonstrating the issue:

    public class Foo {
      public void bar() {
        Map<Id, Account> accs = new Map<Id, Account>([SELECT Name FROM Account]);
      }
    }
    
    

    Expected outcome:

    PMD should report a violation at line 3, but doesn't. This is a false-negative.

    Running PMD through: Apex PMD VS Code Plugin

    a:false-negative 
    opened by jonathanwiesel 0
  • [java] Update rule UnnecessaryWrapperObjectCreation

    [java] Update rule UnnecessaryWrapperObjectCreation

    Describe the PR

    Updates the rule UnnecessaryWrapperObjectCreation. I've removed the check for the java version, as this looked wrong: Boolean.valueOf has been introduced with java 1.4, and all other *.valueOf method with java 1.5. So actually, this rule should have a minimum language version of 1.5, but I guess, that doesn't matter anymore.

    The rule is also directly deprecated, as the new UnnecessaryBoxing replaces it.

    The only useful check of this rule is this: Integer.valueOf(1).toString() - calls to "toString()", where one should simply use String.valueOf(1) instead or Integer.toString(1).

    Related issues

    • Part of #2701
    • Relates to #3364

    Ready?

    • [x] Added unit tests for fixed bug/feature
    • [x] Passing all unit tests
    • [x] Complete build ./mvnw clean verify passes (checked automatically by github actions)
    • [x] Added (in-code) documentation (if needed)
    is:deprecation 
    opened by adangel 4
  • [core] Respect the language version from the command-line

    [core] Respect the language version from the command-line

    Store the language version provided by the command-line arguments and use that as the default language instead of just using the filename

    Describe the PR

    The -language parameter from the CLI was previously being ignored. The language used to analyse a file was just based on the file extension. This meant that it was hard to analyse languages that shared the same file extension, or where the source files conventionally used the "wrong" extension.

    This is highlighted in #1540 and #2133

    The fix here records the language as specified on the command line (if any), and then uses that as the default language for analysis. If no language is supplied, the original behaviour is maintained - looking at the file extension.

    Note: I was only able to add a fairly simple unit test for the first part of this. Running the whole end-to-end CLI is tricky. However, I built with Maven and the original tests work. It may be good to add more tests to net.sourceforge.pmd.it.AllRulesIT once we have other standard rulesets which leverage this functionality.

    NB this is my first PR on PMD, so apologies if anything is missing/wrong!

    Related issues

    • Fixes #1540
    • Fixes #2133

    Ready?

    • [ somewhat ] Added unit tests for fixed bug/feature
    • [ yes ] Passing all unit tests
    • [ yes ] Complete build ./mvnw clean verify passes (checked automatically by github actions)
    • [ yes ] Added (in-code) documentation (if needed)
    opened by aidan-harding 7
Releases(pmd_releases/6.36.0)
  • pmd_releases/6.36.0(Jun 26, 2021)

    26-June-2021 - 6.36.0

    The PMD team is pleased to announce PMD 6.36.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Improved Incremental Analysis

    Incremental Analysis has long helped our users obtain faster analysis results, however, its implementation tended to be too cautious in detecting changes to the runtime and type resolution classpaths, producing more cache invalidations than necessary. We have now improved the heuristics to remove several bogus invalidations, and slightly sped up the cache usage along the way.

    PMD will now ignore:

    • Non class files in classpath and jar / zip files being referenced.
    • Changes to the order of file entries within a jar / zip
    • Changes to file metadata within jar / zip (ie: creation and modification time, significant in multi-module / composite build projects where lateral artifacts are frequently recreated)

    New rules

    • The new Apex rule AvoidDebugStatements finds usages of System.debug calls. Debug statements contribute to longer transactions and consume Apex CPU time even when debug logs are not being captured. You can try out this rule like so:
        <rule ref="category/apex/performance.xml/AvoidDebugStatements" />
    
    • The new Apex rule InaccessibleAuraEnabledGetter checks that an AuraEnabled getter is public or global. This is necessary if it is referenced in Lightning components. You can try out this rule like so:
        <rule ref="category/apex/errorprone.xml/InaccessibleAuraEnabledGetter" />
    

    Renamed rules

    • The Java rule BadComparison has been renamed to ComparisonWithNaN to better reflect what the rule actually detects. It now considers usages of Double.NaN or Float.NaN in more cases and fixes false negatives.

    Fixed Issues

    • apex
      • #3307: [apex] Avoid debug statements since it impact performance
      • #3321: [apex] New rule to detect inaccessible AuraEnabled getters (summer '21 security update)
      • #3332: [apex] CognitiveComplexity - incorrect increment for "else if"
    • core
      • #2637: [cpd] Error Loading stylesheet cpdhtml.xslt
      • #3323: [core] Adds fullDescription and tags in SARIF report
    • java-bestpractices
      • #957: [java] GuardLogStatement: False positive with compile-time constant arguments
      • #3076: [java] UnusedAssignment reports unused variable when used in increment expr
      • #3114: [java] UnusedAssignment false positive when reporting unused variables
      • #3315: [java] LiteralsFirstInComparisons false positive with two constants
      • #3341: [java] JUnitTestsShouldIncludeAssert should support Junit 5
      • #3340: [java] NullPointerException applying rule GuardLogStatement
    • java-codestyle
      • #3317: [java] Update UnnecessaryImport to recognize usage of imported types in javadoc's @exception tag
    • java-errorprone
      • #2895: [java] Improve BadComparison and rename to ComparisonWithNaN
      • #3284: [java] InvalidLogMessageFormat may examine the value of a different but identically named String variable
      • #3304: [java] NPE in MoreThanOneLoggerRule on a java 16 record
      • #3305: [java] ConstructorCallsOverridableMethodRule IndexOutOfBoundsException on a java16 record
      • #3343: [java] CloneMethodMustImplementCloneable: FN with local classes
    • java-performance
      • #3331: [java] UseArraysAsList false negative with for-each loop
      • #3344: [java] InefficientEmptyStringCheck FN with trim.length on method call

    API Changes

    No changes.

    External Contributions

    • #3276: [apex] Update ApexCRUDViolation and OperationWithLimitsInLoop docs - Jonathan Wiesel
    • #3306: [java] More than one logger rule test null pointer exception - Arnaud Jeansen
    • #3317: [java] Update UnnecessaryImport to recognize usage of imported types in javadoc's @exception tag - Piotrek Żygieło
    • #3319: [apex] New AvoidDebugStatements rule to mitigate performance impact - Jonathan Wiesel
    • #3320: [java] Fix incorrect increment for "else if" branch in Cognitive Complexity docs - Denis Borovikov
    • #3322: [apex] added rule to detect inaccessible AuraEnabled getters - Philippe Ozil
    • #3323: [core] Adds fullDescription and tags in SARIF report - Clint Chester
    • #3339: [java] JUnitTestsShouldIncludeAssert Tweak assertion definition to avoid false positive with modern JUnit5 - Arnaud Jeansen

    Stats

    • 81 commits
    • 36 closed tickets & PRs
    • Days since last release: 28
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.36.0.zip(42.46 MB)
    pmd-doc-6.36.0.zip(4.44 MB)
    pmd-src-6.36.0.zip(13.88 MB)
  • pmd_releases/6.35.0(May 29, 2021)

    29-May-2021 - 6.35.0

    The PMD team is pleased to announce PMD 6.35.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Javascript module now requires at least Java 8

    The latest version of Rhino, the implementation of JavaScript we use for parsing JavaScript code, requires at least Java 8. Therefore we decided to upgrade the pmd-javascript module to Java 8 as well. This means that from now on, a Java 8 or later runtime is required in order to analyze JavaScript code. Note that PMD core still only requires Java 7.

    New rules

    This release ships with 3 new Java rules.

        <rule ref="category/java/bestpractices.xml/JUnit5TestShouldBePackagePrivate" />
    
    • CognitiveComplexity uses the cognitive complexity metric to find overly complex code. This metric improves on the similar cyclomatic complexity in several ways, for instance, it incentivizes using clearly readable shorthands and idioms. See the rule documentation for more details. You can try out this rule like so:
        <rule ref="category/java/design.xml/CognitiveComplexity" />
    
    • MutableStaticState finds non-private static fields that are not final. These fields break encapsulation since these fields can be modified from anywhere within the program. You can try out this rule like so:
        <rule ref="category/java/design.xml/MutableStaticState" />
    

    Modified rules

    • The Java rule CompareObjectsWithEquals has now a new property typesThatCompareByReference. With that property, you can configure types, that should be whitelisted for comparison by reference. By default, java.lang.Enum and java.lang.Class are allowed, but you could add custom types here. Additionally comparisons against constants are allowed now. This makes the rule less noisy when two constants are compared. Constants are identified by looking for an all-caps identifier.

    Deprecated rules

    • The java rule DefaultPackage has been deprecated in favor of CommentDefaultAccessModifier.

      The rule "DefaultPackage" assumes that any usage of package-access is accidental, and by doing so, prohibits using a really fundamental and useful feature of the language.

      To satisfy the rule, you have to make the member public even if it doesn't need to, or make it protected, which muddies your intent even more if you don't intend the class to be extended, and may be at odds with other rules like AvoidProtectedFieldInFinalClass.

      The rule CommentDefaultAccessModifier should be used instead. It flags the same thing, but has an escape hatch.

    • The Java rule CloneThrowsCloneNotSupportedException has been deprecated without replacement.

      The rule has no real value as CloneNotSupportedException is a checked exception and therefore you need to deal with it while implementing the clone() method. You either need to declare the exception or catch it. If you catch it, then subclasses can't throw it themselves explicitly. However, Object.clone() will still throw this exception if the Cloneable interface is not implemented.

      Note, this rule has also been removed from the Quickstart Ruleset (rulesets/java/quickstart.xml).

    Fixed Issues

    • apex
      • #3183: [apex] ApexUnitTestMethodShouldHaveIsTestAnnotation false positive with helper method
      • #3243: [apex] Correct findBoundary when traversing AST
    • core
      • #2639: [core] PMD CLI output file is not created if directory or directories in path don't exist
      • #3196: [core] Deprecate ThreadSafeReportListener
    • doc
      • #3230: [doc] Remove "Edit me" button for language index pages
    • dist
      • #2466: [dist] Distribution archive doesn't include all batch scripts
    • java
      • #3269: [java] Fix NPE in MethodTypeResolution
    • java-bestpractices
      • #1175: [java] UnusedPrivateMethod FP with Junit 5 @MethodSource
      • #2219: [java] Document Reasons to Avoid Reassigning Parameters
      • #2737: [java] Fix misleading rule message on rule SwitchStmtsShouldHaveDefault with non-exhaustive enum switch
      • #3236: [java] LiteralsFirstInComparisons should consider constant fields (cont'd)
      • #3239: [java] PMD could enforce non-public methods for Junit5 / Jupiter test methods
      • #3254: [java] AvoidReassigningParameters reports violations on wrong line numbers
    • java-codestyle
      • #2655: [java] UnnecessaryImport false positive for on-demand imports
      • #3206: [java] Deprecate rule DefaultPackage
      • #3262: [java] FieldDeclarationsShouldBeAtStartOfClass: false negative with anon classes
      • #3265: [java] MethodArgumentCouldBeFinal: false negatives with interfaces and inner classes
      • #3266: [java] LocalVariableCouldBeFinal: false negatives with interfaces, anon classes
      • #3274: [java] OnlyOneReturn: false negative with anonymous class
      • #3275: [java] UnnecessaryLocalBeforeReturn: false negatives with lambda and anon class
    • java-design
      • #2780: [java] DataClass example from documentation results in false-negative
      • #2987: [java] New Rule: Public and protected static fields must be final
      • #2329: [java] Cognitive complexity rule for Java
    • java-errorprone
      • #3110: [java] Enhance CompareObjectsWithEquals with list of exceptions
      • #3112: [java] Deprecate rule CloneThrowsCloneNotSupportedException
      • #3205: [java] Make CompareObjectWithEquals allow comparing against constants
      • #3248: [java] Documentation is wrong for SingletonClassReturningNewInstance rule
      • #3249: [java] AvoidFieldNameMatchingTypeName: False negative with interfaces
      • #3268: [java] ConstructorCallsOverridableMethod: IndexOutOfBoundsException with annotations
    • java-performance
      • #1438: [java] InsufficientStringBufferDeclaration false positive for initial calculated StringBuilder size
    • javascript
      • #699: [javascript] Update Rhino library to 1.7.13
      • #2081: [javascript] Failing with OutOfMemoryError parsing a Javascript file

    API Changes

    Deprecated API

    External Contributions

    Stats

    • 143 commits
    • 53 closed tickets & PRs
    • Days since last release: 34
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.35.0.zip(42.45 MB)
    pmd-doc-6.35.0.zip(4.43 MB)
    pmd-src-6.35.0.zip(13.85 MB)
  • pmd_releases/6.34.0(Apr 24, 2021)

    24-April-2021 - 6.34.0

    The PMD team is pleased to announce PMD 6.34.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    New rules

    Modified rules

    • The Apex rule ApexCRUDViolation does not ignore getters anymore and also flags SOQL/SOSL/DML operations without access permission checks in getters. This will produce false positives now for VF getter methods, but we can't reliably detect, whether a getter is a VF getter or not. In such cases, the violation should be suppressed.

    Deprecated rules

    Fixed Issues

    • apex-performance
      • #3198: [apex] OperationWithLimitsInLoopRule: Support more limit consuming static method invocations
    • apex-security
      • #3202: [apex] ApexCRUDViolationRule fails to report CRUD violation on COUNT() queries
      • #3210: [apex] ApexCRUDViolationRule false-negative on non-VF getter
    • java-bestpractices
      • #3190: [java] Use StandardCharsets instead of Charset.forName
      • #3224: [java] UnusedAssignment crashes with nested records
    • java-codestyle
      • #3128: [java] New rule UnnecessaryImport, deprecate DuplicateImports, ImportFromSamePackage, UnusedImports
    • java-errorprone
      • #2757: [java] CloseResource: support Lombok's @Cleanup annotation
      • #3169: [java] CheckSkipResult: NPE when using pattern bindings

    API Changes

    No changes.

    External Contributions

    • #3193: [java] New rule: UseStandardCharsets - Andrea Aime
    • #3198: [apex] OperationWithLimitsInLoopRule: Support more limit consuming static method invocations - Jonathan Wiesel
    • #3211: [apex] ApexCRUDViolationRule: Do not assume method is VF getter to avoid CRUD checks - Jonathan Wiesel
    • #3234: [apex] ApexCRUDViolation: COUNT is indeed CRUD checkable since it exposes data (false-negative) - Jonathan Wiesel

    Stats

    • 74 commits
    • 18 closed tickets & PRs
    • Days since last release: 27
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.34.0.zip(42.36 MB)
    pmd-doc-6.34.0.zip(4.43 MB)
    pmd-src-6.34.0.zip(13.82 MB)
  • pmd_releases/6.33.0(Mar 27, 2021)

    27-March-2021 - 6.33.0

    The PMD team is pleased to announce PMD 6.33.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    PLSQL parsing exclusions

    The PMD PLSQL parser might not parse every valid PL/SQL code without problems. In order to still use PMD on such files, you can now mark certain lines for exclusion from the parser. More information can be found in the language specific documentation for PLSQL.

    Fixed Issues

    • apex-design
      • #3142: [apex] ExcessiveClassLength multiple warning on the same class
    • java
      • #3117: [java] Infinite loop when parsing invalid code nested in lambdas
      • #3145: [java] Parse exception when using "record" as variable name
    • java-bestpractices
      • #3118: [java] UnusedPrivateMethod false positive when passing in lombok.val as argument
      • #3144: [java] GuardLogStatement can have more detailed example
      • #3155: [java] GuardLogStatement: False negative with unguarded method call
      • #3160: [java] MethodReturnsInternalArray does not consider static final fields and fields initialized with empty array
    • java-errorprone
      • #2977: [java] CloseResource: false positive with reassignment detection
      • #3146: [java] InvalidLogMessageFormat detection failing when String.format used
      • #3148: [java] CloseResource false positive with Objects.nonNull
      • #3165: [java] InvalidLogMessageFormat detection failing when String.format used in a variable
    • java-performance
      • #2427: [java] ConsecutiveLiteralAppend false-positive with builder inside lambda
      • #3152: [java] ConsecutiveLiteralAppends and InsufficientStringBufferDeclaration: FP with switch expressions
    • plsql
      • #195: [plsql] Ampersand '&' causes PMD processing error in sql file - Lexical error in file

    External Contributions

    • #3161: [plsql] Add support for lexical parameters in SQL*Plus scripts, allow excluding lines which the parser does not understand - Henning von Bargen
    • #3167: [java] Minor typo in quickstart ruleset - Austin Tice

    Stats

    • 49 commits
    • 27 closed tickets & PRs
    • Days since last release: 28
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.33.0.zip(42.36 MB)
    pmd-doc-6.33.0.zip(4.41 MB)
    pmd-src-6.33.0.zip(13.80 MB)
  • pmd_releases/6.32.0(Feb 27, 2021)

    27-February-2021 - 6.32.0

    The PMD team is pleased to announce PMD 6.32.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Java 16 Support

    This release of PMD brings support for Java 16. PMD supports JEP 394: Pattern Matching for instanceof and JEP 395: Records. Both have been promoted to be a standard language feature of Java 16.

    PMD also supports JEP 397: Sealed Classes (Second Preview) as a preview language feature. In order to analyze a project with PMD that uses these language features, you'll need to enable it via the environment variable PMD_JAVA_OPTS and select the new language version 16-preview:

    export PMD_JAVA_OPTS=--enable-preview
    ./run.sh pmd -language java -version 16-preview ...
    

    Note: Support for Java 14 preview language features have been removed. The version "14-preview" is no longer available.

    Modified Rules

    • The Apex rule ApexDoc has two new properties: reportPrivate and reportProtected. Previously the rule only considered public and global classes, methods, and properties. With these properties, you can verify the existence of ApexDoc comments for private and protected methods as well. By default, these properties are disabled to preserve backwards compatible behavior.

    Fixed Issues

    • apex-documentation
      • #3075: [apex] ApexDoc should support private access modifier
    • java
      • #3101: [java] NullPointerException when running PMD under JRE 11
    • java-bestpractices
      • #3132: [java] UnusedImports with static imports on subclasses
    • java-errorprone
      • #2716: [java] CompareObjectsWithEqualsRule: False positive with Enums
      • #3089: [java] CloseResource rule throws exception on spaces in property types
      • #3133: [java] InvalidLogMessageFormat FP with StringFormattedMessage and ParameterizedMessage
    • plsql
      • #3106: [plsql] ParseException while parsing EXECUTE IMMEDIATE 'drop database link ' || linkname;

    API Changes

    Experimental APIs

    Internal API

    Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. You can identify them with the @InternalApi annotation. You'll also get a deprecation warning.

    • The protected or public member of the Java rule AvoidUsingHardCodedIPRule are deprecated and considered to be internal API. They will be removed with PMD 7.

    External Contributions

    Stats

    • 43 commits
    • 21 closed tickets & PRs
    • Days since last release: 27
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.32.0.zip(42.35 MB)
    pmd-doc-6.32.0.zip(4.41 MB)
    pmd-src-6.32.0.zip(13.78 MB)
  • pmd_releases/6.31.0(Jan 30, 2021)

    30-January-2021 - 6.31.0

    The PMD team is pleased to announce PMD 6.31.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    SARIF Format

    PMD now supports the Static Analysis Results Interchange Format (SARIF) as an additional report format. Just use the command line parameter -format sarif to select it. SARIF is an OASIS standard format for static analysis tools. PMD creates SARIF JSON files in SARIF version 2.1.0. An example report can be found in the documentation in Report formats for PMD.

    CPD

    • The C++ module now supports the new option --ignore-literal-sequences, which can be used to avoid detection of some uninteresting clones. This options has been introduced with PMD 6.30.0 for C# and is now available for C++ as well. See #2963.

    New Rules

    • The new Apex rule OverrideBothEqualsAndHashcode brings the well known Java rule to Apex. In Apex the same principle applies: equals and hashCode should always be overridden together to ensure collection classes such as Maps and Sets work as expected.

    • The new Visualforce rule VfHtmlStyleTagXss checks for potential XSS problems when using <style> tags on Visualforce pages.

    Deprecated rules

    • java-performance
      • AvoidUsingShortType: arithmetic on shorts is not significantly slower than on ints, whereas using shorts may provide significant memory savings in arrays.
      • SimplifyStartsWith: the suggested code transformation has an insignificant performance impact, and decreases readability.

    Fixed Issues

    • core
      • #2953: [core] Support SARIF JSON Format
      • #2970: [core] PMD 6.30.0 release is not reproducible
      • #2994: [core] Fix code climate severity strings
    • java-bestpractices
      • #575: [java] LiteralsFirstInComparisons should consider constant fields
      • #2454: [java] UnusedPrivateMethod violation for disabled class in 6.23.0
      • #2833: [java] NPE in UseCollectionIsEmptyRule with enums
      • #2876: [java] UnusedPrivateField cannot override ignored annotations property
      • #2957: [java] Ignore unused declarations that have special name
    • java-codestyle
      • #2960: [java] Thread issue in MethodNamingConventionsRule
    • java-design
      • #3006: [java] NPE in SingularFieldRule with concise resource syntax
    • java-errorprone
      • #2976: [java] CompareObjectsWithEquals: FP with array.length
      • #2977: [java] 6.30.0 introduces new false positive in CloseResource rule?
      • #2979: [java] UseEqualsToCompareStrings: FP with "var" variables
      • #3004: [java] UseEqualsToCompareStrings false positive with PMD 6.30.0
      • #3062: [java] CloseResource FP with reassigned stream
    • java-performance
      • #2296: [java] Deprecate rule AvoidUsingShortType
      • #2740: [java] Deprecate rule SimplifyStartsWith
      • #3088: [java] AvoidInstantiatingObjectsInLoops - false positive with Collections
    • vf-security
      • #3081: [vf] VfUnescapeEl: Inherently un-XSS-able built-in functions trigger false positives

    API Changes

    Deprecated API

    Experimental APIs

    • The method GenericToken#getKind has been added as experimental. This unifies the token interface for both JavaCC and Antlr. The already existing method AntlrToken#getKind is therefore experimental as well. The returned constant depends on the actual language and might change whenever the grammar of the language is changed.

    External Contributions

    Stats

    • 116 commits
    • 40 closed tickets & PRs
    • Days since last release: 49
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.31.0.zip(42.34 MB)
    pmd-doc-6.31.0.zip(4.41 MB)
    pmd-src-6.31.0.zip(13.75 MB)
  • pmd_releases/6.30.0(Dec 12, 2020)

    12-December-2020 - 6.30.0

    The PMD team is pleased to announce PMD 6.30.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    CPD

    • The C# module now supports the new option --ignore-literal-sequences, which can be used to avoid detection of some uninteresting clones. Support for other languages may be added in the future. See #2945

    • The Scala module now supports suppression through CPD-ON/CPD-OFF comment pairs. See #2929

    Type information for VisualForce

    The Visualforce AST now can resolve the data type of Visualforce expressions that reference Apex Controller properties and Custom Object fields. This feature improves the precision of existing rules, like VfUnescapeEl.

    This can be configured using two environment variables:

    • PMD_VF_APEXDIRECTORIES: Comma separated list of directories for Apex classes. Absolute or relative to the Visualforce directory. Default is ../classes. Specifying an empty string will disable data type resolution for Apex Controller properties.
    • PMD_VF_OBJECTSDIRECTORIES: Comma separated list of directories for Custom Objects. Absolute or relative to the Visualforce directory. Default is ../objects. Specifying an empty string will disable data type resolution for Custom Object fields.

    This feature is experimental, in particular, expect changes to the way the configuration is specified. We'll probably extend the CLI instead of relying on environment variables in a future version.

    Thanks to Jeff Bartolotta and Roopa Mohan for contributing this!

    Fixed Issues

    • core
      • #1939: [core] XPath expressions return handling
      • #1961: [core] Text renderer should include name of violated rule
      • #2874: [core] Fix XMLRenderer with UTF-16
    • cs
      • #2938: [cs] CPD: ignoring using directives could not be disabled
    • java
      • #2911: [java] ClassTypeResolver#searchNodeNameForClass leaks memory
      • #2934: [java] CompareObjectsWithEquals / UseEqualsToCompareStrings - False negatives with fields
      • #2940: [java] Catch additional TypeNotPresentExceptions / LinkageErrors
    • scala
      • #2480: [scala] Support CPD suppressions

    API Changes

    Deprecated API

    Around RuleSet parsing
    Around the PMD class

    Many classes around PMD's entry point (PMD) have been deprecated as internal, including:

    Miscellaneous

    Internal API

    Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. You can identify them with the @InternalApi annotation. You'll also get a deprecation warning.

    External Contributions

    Stats

    • 190 commits
    • 25 closed tickets & PRs
    • Days since last release: 49
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.30.0.zip(42.28 MB)
    pmd-doc-6.30.0.zip(4.40 MB)
    pmd-src-6.30.0.zip(13.70 MB)
  • pmd_releases/6.29.0(Oct 24, 2020)

    24-October-2020 - 6.29.0

    The PMD team is pleased to announce PMD 6.29.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Updated Apex Support

    New Rules

    • The new Apex rule OperationWithLimitsInLoop (apex-performance) finds operations in loops that may hit governor limits such as DML operations, SOQL queries and more. The rule replaces the three rules "AvoidDmlStatementsInLoops", "AvoidSoqlInLoops", and "AvoidSoslInLoops".

    Renamed Rules

    • The Java rule DoNotCallSystemExit has been renamed to DoNotTerminateVM, since it checks for all the following calls: System.exit(int), Runtime.exit(int), Runtime.halt(int). All these calls terminate the Java VM, which is bad, if the VM runs an application server which many independent applications.

    Deprecated Rules

    Fixed Issues

    • apex
      • #2839: [apex] Apex classes with safe navigation operator from Winter 21 (50.0) are skipped
    • apex-performance
      • #1713: [apex] Mark Database DML statements in For Loop
    • core
      • #2831: [core] Fix XMLRenderer newlines when running under IBM Java
    • java-errorprone
      • #2157: [java] Improve DoNotCallSystemExit: permit call in main(), flag System.halt
      • #2764: [java] CloseResourceRule does not recognize multiple assignment done to resource
    • miscellaneous
      • #2823: [doc] Renamed/Moved rules are missing in documentation
    • vf (Salesforce VisualForce)
      • #2765: [vf] Attributes with dot cause a VfParseException

    External Contributions

    Stats

    • 50 commits
    • 23 closed tickets & PRs
    • Days since last release: 27
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.29.0.zip(42.10 MB)
    pmd-doc-6.29.0.zip(4.40 MB)
    pmd-src-6.29.0.zip(13.63 MB)
  • pmd_releases/6.28.0(Sep 26, 2020)

    26-September-2020 - 6.28.0

    The PMD team is pleased to announce PMD 6.28.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    CPD's AnyTokenizer has been improved

    The AnyTokenizer is used for languages, that don't have an own lexer/grammar based tokenizer. AnyTokenizer now handles string literals and end-of-line comments. Fortran, Perl and Ruby have been updated to use AnyTokenizer instead of their old custom tokenizer based on AbstractTokenizer. See #2758 for details.

    AbstractTokenizer and the custom tokenizers of Fortran, Perl and Ruby are deprecated now.

    Fixed Issues

    • cpd

      • #2758: [cpd] Improve AnyTokenizer
      • #2760: [cpd] AnyTokenizer doesn't count columns correctly
    • apex-security

      • #2774: [apex] ApexSharingViolations does not correlate sharing settings with class that contains data access
    • java

      • #2738: [java] Custom rule with @ExhaustiveEnumSwitch throws NPE
      • #2755: [java] [6.27.0] Exception applying rule CloseResource on file ... java.lang.NullPointerException
      • #2756: [java] TypeTestUtil fails with NPE for anonymous class
      • #2767: [java] IndexOutOfBoundsException when parsing an initializer BlockStatement
      • #2783: [java] Error while parsing with lambda of custom interface
    • java-bestpractices

      • #2759: [java] False positive in UnusedAssignment
    • java-design

      • #2708: [java] False positive FinalFieldCouldBeStatic when using lombok Builder.Default

    API Changes

    Deprecated API

    For removal

    External Contributions

    • #2735: [ci] Add github actions for a fast view of pr succeed/not - XenoAmess
    • #2747: [java] Don't trigger FinalFieldCouldBeStatic when field is annotated with lombok @Builder.Default - Ollie Abbey
    • #2773: [java] issue-2738: Adding null check to avoid npe when switch case is default - Nimit Patel
    • #2789: Add badge for reproducible build - Dan Rollo
    • #2791: [apex] Analyze inner classes for sharing violations - Jeff Bartolotta

    Stats

    • 58 commits
    • 24 closed tickets & PRs
    • Days since last release: 25
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.28.0.zip(42.08 MB)
    pmd-doc-6.28.0.zip(4.39 MB)
    pmd-src-6.28.0.zip(13.61 MB)
  • pmd_releases/6.27.0(Aug 31, 2020)

    31-August-2020 - 6.27.0

    The PMD team is pleased to announce PMD 6.27.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Java 15 Support

    This release of PMD brings support for Java 15. PMD can parse Text Blocks which have been promoted to be a standard language feature of Java.

    PMD also supports Pattern Matching for instanceof, Records, and Sealed Classes.

    Note: The Pattern Matching for instanceof, Records, and Sealed Classes are all preview language features of OpenJDK 15 and are not enabled by default. In order to analyze a project with PMD that uses these language features, you'll need to enable it via the environment variable PMD_JAVA_OPTS and select the new language version 15-preview:

    export PMD_JAVA_OPTS=--enable-preview
    ./run.sh pmd -language java -version 15-preview ...
    

    Note: Support for Java 13 preview language features have been removed. The version "13-preview" is no longer available.

    Changes in how tab characters are handled

    In the past, tab characters in source files has been handled differently in different languages by PMD. For instance in Java, tab characters had a width of 8 columns, while C# used only 1 column. Visualforce instead used 4 columns.

    This has been unified now so that tab characters are consistently now always 1 column wide.

    This however might be a incompatible change, if you're using the properties "BeginColumn" or "EndColumn" additionally to "BeginLine" and "EndLine" of a Token/AST node in order to highlight where a rule violation occurred in the source file. If you have logic there that deals with tab characters, you most likely can remove this logic now, since tab characters are now just "normal" characters in terms of string processing.

    See also [all] Ensure PMD/CPD uses tab width of 1 for tabs consistently #2656.

    Updated PMD Designer

    This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.

    New Rules

    • The new Java rule AvoidReassigningCatchVariables (java-bestpractices) finds cases where the variable of the caught exception is reassigned. This practice is surprising and prevents further evolution of the code like multi-catch.

    Modified Rules

    • The Java rule CloseResource (java-errorprone) has a new property closeNotInFinally. With this property set to true the rule will also find calls to close a resource, which are not in a finally-block of a try-statement. If a resource is not closed within a finally block, it might not be closed at all in case of exceptions.

      As this new detection would yield many new violations, it is disabled by default. It might be enabled in a later version of PMD.

    Deprecated Rules

    Fixed Issues

    • core
      • #724: [core] Avoid parsing rulesets multiple times
      • #1962: [core] Simplify Report API
      • #2653: [lang-test] Upgrade kotlintest to Kotest
      • #2656: [all] Ensure PMD/CPD uses tab width of 1 for tabs consistently
      • #2690: [core] Fix java7 compatibility
    • java
      • #2646: [java] Support JDK 15
    • java-bestpractices
      • #2471: [java] New Rule: AvoidReassigningCatchVariables
      • #2663: [java] NoClassDefFoundError on upgrade from 6.25.0 to 6.26.0
      • #2668: [java] UnusedAssignment false positives
      • #2673: [java] UnusedPrivateField and SingularField false positive with lombok annotation EqualsAndHashCode
      • #2684: [java] UnusedAssignment FP in try/catch
      • #2686: [java] UnusedAssignment must not flag abstract method parameters in interfaces and abstract classes
    • java-design
      • #2108: [java] [doc] ImmutableField rule: Description should clarify shallow immutability
      • #2461: [java] ExcessiveParameterListRule must ignore a private constructor
    • java-errorprone
      • #2264: [java] SuspiciousEqualsMethodName: Improve description about error-prone overloading of equals()
      • #2410: [java] ProperCloneImplementation not valid for final class
      • #2431: [java] InvalidLogMessageFormatRule throws IndexOutOfBoundsException when only logging exception message
      • #2439: [java] AvoidCatchingThrowable can not detect the case: catch (java.lang.Throwable t)
      • #2470: [java] CloseResource false positive when resource included in return value
      • #2531: [java] UnnecessaryCaseChange can not detect the case like: foo.equals(bar.toLowerCase())
      • #2647: [java] Deprecate rule DataFlowAnomalyAnalysis
    • java-performance
      • #1868: [java] false-positive for SimplifyStartsWith if string is empty
      • #2441: [java] RedundantFieldInitializer can not detect a special case for char initialize: char foo = '\0';
      • #2530: [java] StringToString can not detect the case: getStringMethod().toString()
    • dart
      • #2750: [dart] [cpd] Cpd Dart escaped dollar

    API Changes

    • XML rule definition in rulesets: In PMD 7, the language attribute will be required on all rule elements that declare a new rule. Some base rule classes set the language implicitly in their constructor, and so this is not required in all cases for the rule to work. But this behavior will be discontinued in PMD 7, so missing language attributes are now reported as a forward compatibility warning.

    Deprecated API

    For removal

    External Contributions

    Stats

    • 189 commits
    • 68 closed tickets & PRs
    • Days since last release: 37
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.27.0.zip(41.96 MB)
    pmd-doc-6.27.0.zip(4.39 MB)
    pmd-src-6.27.0.zip(13.89 MB)
  • pmd_releases/6.26.0(Jul 25, 2020)

    25-July-2020 - 6.26.0

    The PMD team is pleased to announce PMD 6.26.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    New Rules

    • The new Java rule UnusedAssignment (java-bestpractices) finds assignments to variables, that are never used and are useless. The new rule is supposed to entirely replace DataflowAnomalyAnalysis.

    Modified rules

    • The Java rule ArrayIsStoredDirectly (java-bestpractices) now ignores by default private methods and constructors. You can restore the old behavior by setting the new property allowPrivate to "false".

    Fixed Issues

    • apex
      • #2610: [apex] Support top-level enums in rules
    • apex-bestpractices
      • #2626: [apex] UnusedLocalVariable - false positive on case insensitivity allowed in Apex
    • apex-performance
      • #2598: [apex] AvoidSoqlInLoops false positive for SOQL with in For-Loop
    • apex-security
      • #2620: [visualforce] False positive on VfUnescapeEl with new Message Channel feature
    • core
      • #710: [core] Review used dependencies
      • #2594: [core] Update exec-maven-plugin and align it in all project
      • #2615: [core] PMD/CPD produces invalid XML (insufficient escaping/wrong encoding)
    • java-bestpractices
      • #2543: [java] UseCollectionIsEmpty can not detect the case this.foo.size()
      • #2569: [java] LiteralsFirstInComparisons: False negative for methods returning Strings
      • #2622: [java] ArrayIsStoredDirectly false positive with private constructor/methods
    • java-codestyle
      • #2546: [java] DuplicateImports reported for the same import... and import static...
    • java-design
      • #2174: [java] LawOfDemeter: False positive with 'this' pointer
      • #2181: [java] LawOfDemeter: False positive with indexed array access
      • #2189: [java] LawOfDemeter: False positive when casting to derived class
      • #2580: [java] AvoidThrowingNullPointerException marks all NullPointerException objects as wrong, whether or not thrown
      • #2625: [java] NPathComplexity can't handle switch expressions
    • java-errorprone
      • #2578: [java] AvoidCallingFinalize detects some false positives
      • #2634: [java] NullPointerException in rule ProperCloneImplementation
    • java-performance
      • #1736: [java] UseStringBufferForStringAppends: False positive if only one concatenation
      • #2207: [java] AvoidInstantiatingObjectsInLoops: False positive - should not flag objects when assigned to lists/arrays

    API Changes

    Deprecated API

    For removal

    External Contributions

    Stats

    • 156 commits
    • 43 closed tickets & PRs
    • Days since last release: 28
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.26.0.zip(42.12 MB)
    pmd-doc-6.26.0.zip(4.38 MB)
    pmd-src-6.26.0.zip(13.51 MB)
  • pmd_releases/6.25.0(Jun 27, 2020)

    27-June-2020 - 6.25.0

    The PMD team is pleased to announce PMD 6.25.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Scala cross compilation

    Up until now the PMD Scala module has been compiled against scala 2.13 only by default. However, this makes it impossible to use pmd as a library in scala projects, that use scala 2.12, e.g. in sbt plugins. Therefore PMD now provides cross compiled pmd-scala modules for both versions: scala 2.12 and scala 2.13.

    The new modules have new maven artifactIds. The old artifactId net.sourceforge.pmd:pmd-scala:6.25.0 is still available, but is deprecated from now on. It has been demoted to be just a delegation to the new pmd-scala_2.13 module and will be removed eventually.

    The coordinates for the new modules are:

    <dependency>
        <groupId>net.sourceforge.pmd</groupId>
        <artifactId>pmd-scala_2.12</artifactId>
        <version>6.25.0</version>
    </dependency>
    
    <dependency>
        <groupId>net.sourceforge.pmd</groupId>
        <artifactId>pmd-scala_2.13</artifactId>
        <version>6.25.0</version>
    </dependency>
    

    The command line version of PMD continues to use scala 2.13.

    New Rules

    • The new Java Rule UnnecessaryCast (java-codestyle) finds casts that are unnecessary while accessing collection elements.

    • The new Java Rule AvoidCalendarDateCreation (java-performance) finds usages of java.util.Calendar whose purpose is just to get the current date. This can be done in a more lightweight way.

    • The new Java Rule UseIOStreamsWithApacheCommonsFileItem (java-performance) finds usage of FileItem.get() and FileItem.getString(). These two methods are problematic since they load the whole uploaded file into memory.

    Modified rules

    • The Java rule UseDiamondOperator (java-codestyle) now by default finds unnecessary usages of type parameters, which are nested, involve wildcards and are used within a ternary operator. These usages are usually only unnecessary with Java8 and later, when the type inference in Java has been improved.

      In order to avoid false positives when checking Java7 only code, the rule has the new property java7Compatibility, which is disabled by default. Settings this to "true" retains the old rule behaviour.

    Fixed Issues

    • apex-bestpractices
      • #2554: [apex] Exception applying rule UnusedLocalVariable on trigger
    • core
      • #971: [apex][plsql][java] Deprecate overly specific base rule classes
      • #2451: [core] Deprecate support for List attributes with XPath 2.0
      • #2599: [core] Fix XPath 2.0 Rule Chain Analyzer with Unions
      • #2483: [lang-test] Support cpd tests based on text comparison. For details see Testing your implementation in the developer documentation.
    • c#
      • #2551: [c#] CPD suppression with comments doesn't work
    • cpp
      • #1757: [cpp] Support unicode characters
    • java
      • #2549: [java] Auxclasspath in PMD CLI does not support relative file path
    • java-codestyle
      • #2545: [java] UseDiamondOperator false negatives
      • #2573: [java] DefaultPackage: Allow package default JUnit 5 Test methods
    • java-design
      • #2563: [java] UselessOverridingMethod false negative with already public methods
      • #2570: [java] NPathComplexity should mention the expected NPath complexity
    • java-errorprone
      • #2544: [java] UseProperClassLoader can not detect the case with method call on intermediate variable
    • java-performance
      • #2591: [java] InefficientStringBuffering/AppendCharacterWithChar: Fix false negatives with concats in appends
      • #2600: [java] UseStringBufferForStringAppends: fix false negative with fields
    • scala
      • #2547: [scala] Add cross compilation for scala 2.12 and 2.13

    API Changes

    • The maven module net.sourceforge.pmd:pmd-scala is deprecated. Use net.sourceforge.pmd:pmd-scala_2.13 or net.sourceforge.pmd:pmd-scala_2.12 instead.

    • Rule implementation classes are internal API and should not be used by clients directly. The rules should only be referenced via their entry in the corresponding category ruleset (e.g. <rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod" />).

      While we definitely won't move or rename the rule classes in PMD 6.x, we might consider changes in PMD 7.0.0 and onwards.

    Deprecated APIs

    Internal API

    Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. You can identify them with the @InternalApi annotation. You'll also get a deprecation warning.

    For removal

    External Contributions

    Stats

    • 135 commits
    • 31 closed tickets & PRs
    • Days since last release: 33
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.25.0.zip(59.53 MB)
    pmd-doc-6.25.0.zip(4.38 MB)
    pmd-src-6.25.0.zip(14.42 MB)
  • pmd_releases/6.24.0(May 24, 2020)

    24-May-2020 - 6.24.0

    The PMD team is pleased to announce PMD 6.24.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    CPD now supports XML as well

    Thanks to Fernando Cosso CPD can now find duplicates in XML files as well. This is useful to find duplicated sections in XML files.

    Updated PMD Designer

    This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.

    New Rules

    • The new Java Rule LiteralsFirstInComparisons (java-bestpractices) find String literals, that are used in comparisons and are not positioned first. Using the String literal as the receiver of e.g. equals helps to avoid NullPointerExceptions.

      This rule is replacing the two old rules PositionLiteralsFirstInComparisons and PositionLiteralsFirstInCaseInsensitiveComparisons and extends the check for the methods compareTo, compareToIgnoreCase and contentEquals in addition to equals and equalsIgnoreCase.

      Note: This rule also replaces the two mentioned rules in Java's quickstart ruleset.

    Deprecated Rules

    Fixed Issues

    • apex-bestpractices
      • #2468: [apex] Unused Local Variable fails on blocks
    • core
      • #2444: [core] Support reproducible builds
      • #2484: [core] Update maven-enforcer-plugin to require Java 118
    • c#
      • #2495: [c#] Support for interpolated verbatim strings
    • java
      • #2472: [java] JavaCharStream throws an Error on invalid escape
    • java-bestpractices
      • #2145: [java] Deprecate rules PositionLiteralsFirstIn(CaseInsensitive)Comparisons in favor of LiteralsFirstInComparisons
      • #2288: [java] JUnitTestsShouldIncludeAssert: Add support for Hamcrest MatcherAssert.assertThat
      • #2437: [java] AvoidPrintStackTrace can't detect the case e.getCause().printStackTrace()
    • java-codestyle
      • #2476: [java] MethodNamingConventions - Add support for JUnit 5 method naming
    • java-errorprone
      • #2477: [java] JUnitSpelling false-positive for JUnit5/4 tests
    • swift
      • #2473: [swift] Swift 5 (up to 5.2) support for CPD

    API Changes

    Deprecated APIs

    Experimental APIs

    Note: Experimental APIs are identified with the annotation Experimental, see its javadoc for details

    External Contributions

    Stats

    • 114 commits
    • 29 closed tickets & PRs
    • Days since last release: 30
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.24.0.zip(59.52 MB)
    pmd-doc-6.24.0.zip(4.37 MB)
    pmd-src-6.24.0.zip(14.25 MB)
  • pmd_releases/6.23.0(Apr 24, 2020)

    24-April-2020 - 6.23.0

    The PMD team is pleased to announce PMD 6.23.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    PMD adopts Contributor Code of Conduct

    To facilitate healthy and constructive community behavior PMD adopts Contributor Convenant as its code of conduct.

    Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

    You can find the code of conduct in the file code_of_conduct.md in our repository.

    Performance improvements for XPath 2.0 rules

    XPath rules written with XPath 2.0 now support conversion to a rulechain rule, which improves their performance. The rulechain is a mechanism that allows several rules to be executed in a single tree traversal. Conversion to the rulechain is possible if your XPath expression looks like //someNode/... | //someOtherNode/... | ..., that is, a union of one or more path expressions that start with //. Instead of traversing the whole tree once per path expression (and per rule), a single traversal executes all rules in your ruleset as needed.

    This conversion is performed automatically and cannot be disabled. The conversion should not change the result of your rules, if it does, please report a bug at https://github.com/pmd/pmd/issues

    Note that XPath 1.0 support, the default XPath version, is deprecated since PMD 6.22.0. We highly recommend that you upgrade your rules to XPath 2.0. Please refer to the migration guide.

    Javascript improvements for ES6

    PMD uses the Rhino library to parse Javascript. The default version has been set to ES6, so that some ECMAScript 2015 features are supported. E.g. let statements and for-of loops are now parsed. However Rhino does not support all features.

    New JSON renderer

    PMD now supports a JSON renderer (use it with -f json on the CLI). See the documentation and example

    New Rules

    Fixed Issues

    • apex-design
      • #2358: [apex] Invalid Apex in Cognitive Complexity tests
    • apex-security
      • #2210: [apex] ApexCRUDViolation: Support WITH SECURITY_ENFORCED
      • #2399: [apex] ApexCRUDViolation: false positive with security enforced with line break
    • core
      • #1286: [core] Export Supporting JSON Format
      • #2019: [core] Insufficient deprecation warnings for XPath attributes
      • #2357: Add code of conduct: Contributor Covenant
      • #2426: [core] CodeClimate renderer links are dead
      • #2432: [core] Close ZIP data sources even if a runtime exception or error is thrown
    • doc
      • #2355: [doc] Improve documentation about incremental analysis
      • #2356: [doc] Add missing doc about pmd.github.io
      • #2412: [core] HTMLRenderer doesn't render links to source files
      • #2413: [doc] Improve documentation about the available renderers (PMD/CPD)
    • java
      • #2378: [java] AbstractJUnitRule has bad performance on large code bases
    • java-bestpractices
      • #2398: [java] AbstractClassWithoutAbstractMethod false negative with inner abstract classes
    • java-codestyle
      • #1164: [java] ClassNamingConventions suggests to add Util for class containing only static constants
      • #1723: [java] UseDiamondOperator false-positive inside lambda
    • java-design
      • #2390: [java] AbstractClassWithoutAnyMethod: missing violation for nested classes
    • java-errorprone
      • #2402: [java] CloseResource possible false positive with Primitive Streams
    • java-multithreading
      • #2313: [java] Documenation for DoNotUseThreads is outdated
    • javascript
      • #1235: [javascript] Use of let results in an Empty Statement in the AST
      • #2379: [javascript] Support for-of loop
    • javascript-errorprone
      • #384: [javascript] Trailing commas not detected on French default locale

    API Changes

    Deprecated APIs

    Internal API

    Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. You can identify them with the @InternalApi annotation. You'll also get a deprecation warning.

    In ASTs

    As part of the changes we'd like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. The following usages are now deprecated in the Apex, Javascript, PL/SQL, Scala and Visualforce ASTs:

    • Manual instantiation of nodes. Constructors of node classes are deprecated and marked InternalApi. Nodes should only be obtained from the parser, which for rules, means that they never need to instantiate node themselves. Those constructors will be made package private with 7.0.0.
    • Subclassing of abstract node classes, or usage of their type. The base classes are internal API and will be hidden in version 7.0.0. You should not couple your code to them.
      • In the meantime you should use interfaces like VfNode or Node, or the other published interfaces in this package, to refer to nodes generically.
      • Concrete node classes will be made final with 7.0.0.
    • Setters found in any node class or interface. Rules should consider the AST immutable. We will make those setters package private with 7.0.0.
    • The implementation classes of Parser (eg VfParser) are deprecated and should not be used directly. Use LanguageVersionHandler#getParser instead.
    • The implementation classes of TokenManager (eg VfTokenManager) are deprecated and should not be used outside of our implementation. This also affects CPD-only modules.

    These deprecations are added to the following language modules in this release. Please look at the package documentation to find out the full list of deprecations.

    These deprecations have already been rolled out in a previous version for the following languages:

    Outside of these packages, these changes also concern the following TokenManager implementations, and their corresponding Parser if it exists (in the same package):

    In the Java AST the following attributes are deprecated and will issue a warning when used in XPath rules:

    For removal

    External Contributions

    Stats

    • 237 commits
    • 64 closed tickets & PRs
    • Days since last release: 42
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.23.0.zip(59.55 MB)
    pmd-doc-6.23.0.zip(4.94 MB)
    pmd-src-6.23.0.zip(14.84 MB)
  • pmd_releases/6.22.0(Mar 12, 2020)

    12-March-2020 - 6.22.0

    The PMD team is pleased to announce PMD 6.22.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Java 14 Support

    This release of PMD brings support for Java 14. PMD can parse Switch Expressions, which have been promoted to be a standard language feature of Java.

    PMD also parses Text Blocks as String literals, which is still a preview language feature in Java 14.

    The new Pattern Matching for instanceof can be used as well as Records.

    Note: The Text Blocks, Pattern Matching for instanceof and Records are all preview language features of OpenJDK 14 and are not enabled by default. In order to analyze a project with PMD that uses these language features, you'll need to enable it via the environment variable PMD_JAVA_OPTS and select the new language version 14-preview:

    export PMD_JAVA_OPTS=--enable-preview
    ./run.sh pmd -language java -version 14-preview ...
    

    Note: Support for the extended break statement introduced in Java 12 as a preview language feature has been removed from PMD with this version. The version "12-preview" is no longer available.

    Updated PMD Designer

    This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.

    Apex Suppressions

    In addition to suppressing violation with the @SuppressWarnings annotation, Apex now also supports the suppressions with a NOPMD comment. See Suppressing warnings.

    Improved CPD support for C#

    The C# tokenizer is now based on an antlr grammar instead of a manual written tokenizer. This should give more accurate results and especially fixes the problems with the using statement syntax (see #2139).

    XPath Rules

    See the new documentation about Writing XPath Rules.

    Note: As of PMD version 6.22.0, XPath versions 1.0 and the 1.0 compatibility mode are deprecated. XPath 2.0 is superior in many ways, for example for its support for type checking, sequence values, or quantified expressions. For a detailed but approachable review of the features of XPath 2.0 and above, see the Saxon documentation.

    New Rules

    • The Rule CognitiveComplexity (apex-design) finds methods and classes that are highly complex and therefore difficult to read and more costly to maintain. In contrast to cyclomatic complexity, this rule uses "Cognitive Complexity", which is a measure of how difficult it is for humans to read and understand a method.

    • The Rule TestMethodsMustBeInTestClasses (apex-errorprone) finds test methods that are not residing in a test class. The test methods should be moved to a proper test class. Support for tests inside functional classes was removed in Spring-13 (API Version 27.0), making classes that violate this rule fail compile-time. This rule is however useful when dealing with legacy code.

    Fixed Issues

    • apex
      • #1087: [apex] Support suppression via //NOPMD
      • #2306: [apex] Switch statements are not parsed/supported
    • apex-design
      • #2162: [apex] Cognitive Complexity rule
    • apex-errorprone
      • #639: [apex] Test methods should not be in classes other than test classes
    • cs
      • #2139: [cs] CPD doesn't understand alternate using statement syntax with C# 8.0
    • doc
      • #2274: [doc] Java API documentation for PMD
    • java
      • #2159: [java] Prepare for JDK 14
      • #2268: [java] Improve TypeHelper resilience
    • java-bestpractices
      • #2277: [java] FP in UnusedImports for ambiguous static on-demand imports
    • java-design
      • #911: [java] UselessOverridingMethod false positive when elevating access modifier
    • java-errorprone
      • #2242: [java] False-positive MisplacedNullCheck reported
      • #2250: [java] InvalidLogMessageFormat flags logging calls using a slf4j-Marker
      • #2255: [java] InvalidLogMessageFormat false-positive for a lambda argument
    • java-performance
      • #2275: [java] AppendCharacterWithChar flags literals in an expression
    • plsql
      • #2325: [plsql] NullPointerException while running parsing test for CREATE TRIGGER
      • #2327: [plsql] Parsing of WHERE CURRENT OF
      • #2328: [plsql] Support XMLROOT
      • #2331: [plsql] Fix in Comment statement
      • #2332: [plsql] Fixed Execute Immediate statement parsing
      • #2340: [plsql] Fixed parsing / as divide or execute

    API Changes

    Deprecated APIs

    Internal API

    Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. You can identify them with the @InternalApi annotation. You'll also get a deprecation warning.

    For removal
    In ASTs (JSP)

    As part of the changes we'd like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. The following usages are now deprecated in the JSP AST (with other languages to come):

    • Manual instantiation of nodes. Constructors of node classes are deprecated and marked InternalApi. Nodes should only be obtained from the parser, which for rules, means that they never need to instantiate node themselves. Those constructors will be made package private with 7.0.0.
    • Subclassing of abstract node classes, or usage of their type. The base classes are internal API and will be hidden in version 7.0.0. You should not couple your code to them.
      • In the meantime you should use interfaces like JspNode or Node, or the other published interfaces in this package, to refer to nodes generically.
      • Concrete node classes will be made final with 7.0.0.
    • Setters found in any node class or interface. Rules should consider the AST immutable. We will make those setters package private with 7.0.0.
    • The class JspParser is deprecated and should not be used directly. Use LanguageVersionHandler#getParser instead.

    Please look at net.sourceforge.pmd.lang.jsp.ast to find out the full list of deprecations.

    In ASTs (Velocity)

    As part of the changes we'd like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. The following usages are now deprecated in the VM AST (with other languages to come):

    • Manual instantiation of nodes. Constructors of node classes are deprecated and marked InternalApi. Nodes should only be obtained from the parser, which for rules, means that they never need to instantiate node themselves. Those constructors will be made package private with 7.0.0.
    • Subclassing of abstract node classes, or usage of their type. The base classes are internal API and will be hidden in version 7.0.0. You should not couple your code to them.
      • In the meantime you should use interfaces like VmNode or Node, or the other published interfaces in this package, to refer to nodes generically.
      • Concrete node classes will be made final with 7.0.0.
    • Setters found in any node class or interface. Rules should consider the AST immutable. We will make those setters package private with 7.0.0.
    • The package net.sourceforge.pmd.lang.vm.directive as well as the classes DirectiveMapper and LogUtil are deprecated for removal. They were only used internally during parsing.
    • The class VmParser is deprecated and should not be used directly. Use LanguageVersionHandler#getParser instead.

    Please look at net.sourceforge.pmd.lang.vm.ast to find out the full list of deprecations.

    PLSQL AST

    The production and node ASTCursorBody was unnecessary, not used and has been removed. Cursors have been already parsed as ASTCursorSpecification.

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.22.0.zip(59.48 MB)
    pmd-doc-6.22.0.zip(5.83 MB)
    pmd-src-6.22.0.zip(15.67 MB)
  • 6.21.0-with-designer(Jan 24, 2020)

  • pmd_releases/6.21.0(Jan 24, 2020)

    24-January-2020 - 6.21.0

    The PMD team is pleased to announce PMD 6.21.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Modelica support

    Thanks to Anatoly Trosinenko PMD supports now a new language: Modelica is a language to model complex physical systems. Both PMD and CPD are supported and there are already 3 rules available. The PMD Designer supports syntax highlighting for Modelica.

    While the language implementation is quite complete, Modelica support is considered experimental for now. This is to allow us to change the rule API (e.g. the AST classes) slightly and improve the implementation based on your feedback.

    Simple XML dump of AST

    We added a experimental feature to dump the AST of a source file into XML. The XML format is of course PMD specific and language dependent. That XML file can be used to execute (XPath) queries against without PMD. It can also be used as a textual visualization of the AST if you don't want to use the Designer.

    This feature is experimental and might change or even be removed in the future, if it is not useful. A short description how to use it is available under Creating XML dump of the AST.

    Any feedback about it, especially about your use cases, is highly appreciated.

    Updated Apex Support

    • The Apex language support has been bumped to version 48 (Spring '20). All new language features are now properly parsed and processed.

    CPD XML format

    The CPD XML output format has been enhanced to also report column information for found duplications in addition to the line information. This allows to display the exact tokens, that are considered duplicate.

    If a CPD language doesn't provide these exact information, then these additional attributes are omitted.

    Each <file> element in the XML format now has 3 new attributes:

    • attribute endline
    • attribute column (if there is column information available)
    • attribute endcolumn (if there is column information available)

    Modified Rules

    • The Java rule AvoidLiteralsInIfCondition (java-errorprone) has a new property ignoreExpressions. This property is set by default to true in order to maintain compatibility. If this property is set to false, then literals in more complex expressions are considered as well.

    • The Apex rule ApexCSRF (apex-errorprone) has been moved from category "Security" to "Error Prone". The Apex runtime already prevents DML statements from being executed, but only at runtime. So, if you try to do this, you'll get an error at runtime, hence this is error prone. See also the discussion on #2064.

    • The Java rule CommentRequired (java-documentation) has a new property classCommentRequirement. This replaces the now deprecated property headerCommentRequirement, since the name was misleading. (File) header comments are not checked, but class comments are.

    Fixed Issues

    • apex
      • #2208: [apex] ASTFormalComment should implement ApexNode<T>
    • core
      • #1984: [java] Cyclomatic complexity is misreported (lack of clearing metrics cache)
      • #2006: [core] PMD should warn about multiple instances of the same rule in a ruleset
      • #2161: [core] ResourceLoader is deprecated and marked as internal but is exposed
      • #2170: [core] DocumentFile doesn't preserve newlines
    • doc
      • #2214: [doc] Link broken in pmd documentation for writing Xpath rules
    • java
      • #2212: [java] JavaRuleViolation reports wrong class name
    • java-bestpractices
      • #2149: [java] JUnitAssertionsShouldIncludeMessage - False positive with assertEquals and JUnit5
    • java-codestyle
      • #2167: [java] UnnecessaryLocalBeforeReturn false positive with variable captured by method reference
    • java-documentation
      • #1683: [java] CommentRequired property names are inconsistent
    • java-errorprone
      • #2140: [java] AvoidLiteralsInIfCondition: false negative for expressions
      • #2196: [java] InvalidLogMessageFormat does not detect extra parameters when no placeholders
    • java-performance
      • #2141: [java] StringInstatiation: False negative with String-array access
    • plsql
      • #2008: [plsql] In StringLiteral using alternative quoting mechanism single quotes cause parsing errors
      • #2009: [plsql] Multiple DDL commands are skipped during parsing

    API Changes

    Deprecated APIs

    Internal API

    Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. You can identify them with the @InternalApi annotation. You'll also get a deprecation warning.

    For removal

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.21.0.zip(59.41 MB)
    pmd-doc-6.21.0.zip(5.56 MB)
    pmd-src-6.21.0.zip(15.39 MB)
  • pmd_releases/6.20.0(Nov 29, 2019)

    29-November-2019 - 6.20.0

    The PMD team is pleased to announce PMD 6.20.0.

    This is a minor release.

    Table Of Contents

    Fixed Issues

    • apex
      • #2092: [apex] ApexLexer logs visible when Apex is the selected language upon starting the designer
      • #2136: [apex] Provide access to underlying query of SoqlExpression
    • core
      • #2002: [doc] Issue with http://pmdapplied.com/ linking to a gambling Web site
      • #2062: [core] Shortnames parameter does not work with Ant
      • #2090: [ci] Release notes and draft releases
      • #2096: [core] Referencing category errorprone.xml produces deprecation warnings for InvalidSlf4jMessageFormat
    • java
      • #1861: [java] Be more lenient with version numbers
      • #2105: [java] Wrong name for inner classes in violations
    • java-bestpractices
      • #2016: [java] UnusedImports: False positive if wildcard is used and only static methods
    • java-codestyle
      • #1362: [java] LinguisticNaming flags Predicates with boolean-style names
      • #2029: [java] UnnecessaryFullyQualifiedName false-positive for non-static nested classes
      • #2098: [java] UnnecessaryFullyQualifiedName: regression / false positive
    • java-design
      • #2075: [java] ImmutableField false positive with inner class
      • #2125: [java] ImmutableField: False positive when variable is updated in conditional loop
    • java-errorprone
      • #2102: [java] False positive MissingStaticMethodInNonInstantiatableClass when inheritors are instantiable

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.20.0.zip(58.03 MB)
    pmd-doc-6.20.0.zip(5.53 MB)
    pmd-src-6.20.0.zip(14.15 MB)
  • pmd_releases/6.19.0(Oct 31, 2019)

    31-October-2019 - 6.19.0

    The PMD team is pleased to announce PMD 6.19.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Updated PMD Designer

    This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.

    Java Metrics

    Modified Rules

    • The Java rules InvalidLogMessageFormat and MoreThanOneLogger (java-errorprone) now both support Log4j2. Note that the rule "InvalidSlf4jMessageFormat" has been renamed to "InvalidLogMessageFormat" to reflect the fact, that it now supports more than slf4j.

    • The Java rule LawOfDemeter (java-design) ignores now also Builders, that are not assigned to a local variable, but just directly used within a method call chain. The method, that creates the builder needs to end with "Builder", e.g. newBuilder() or initBuilder() works. This change fixes a couple of false positives.

    • The Java rule DataflowAnomalyAnalysis (java-errorprone) doesn't check for UR anomalies (undefined and then referenced) anymore. These checks were all false-positives, since actual UR occurrences would lead to compile errors.

    • The java rule DoNotUseThreads (java-multithreading) has been changed to not report usages of java.lang.Runnable anymore. Just using Runnable does not automatically create a new thread. While the check for Runnable has been removed, the rule now additionally checks for usages of Executors and ExecutorService. Both create new threads, which are not managed by a J2EE server.

    Renamed Rules

    Fixed Issues

    • core
      • #1978: [core] PMD fails on excluding unknown rules
      • #2014: [core] Making add(SourceCode sourceCode) public for alternative file systems
      • #2020: [core] Wrong deprecation warnings for unused XPath attributes
      • #2036: [core] Wrong include/exclude patterns are silently ignored
      • #2048: [core] Enable type resolution by default for XPath rules
      • #2067: [core] Build issue on Windows
      • #2068: [core] Rule loader should use the same resources loader for the ruleset
      • #2071: [ci] Add travis build on windows
      • #2072: [test][core] Not enough info in "test setup error" when numbers of lines do not match
      • #2082: [core] Incorrect logging of deprecated/renamed rules
    • java
      • #2042: [java] PMD crashes with ClassFormatError: Absent Code attribute...
    • java-bestpractices
      • #1531: [java] UnusedPrivateMethod false-positive with method result
      • #2025: [java] UnusedImports when @see / @link pattern includes a FQCN
    • java-codestyle
      • #2017: [java] UnnecessaryFullyQualifiedName triggered for inner class
    • java-design
      • #1912: [java] Metrics not computed correctly with annotations
    • java-errorprone
      • #336: [java] InvalidSlf4jMessageFormat applies to log4j2
      • #1636: [java] Stop checking UR anomalies for DataflowAnomalyAnalysis
    • java-multithreading
      • #1627: [java] DoNotUseThreads should not warn on Runnable
    • doc
      • #2058: [doc] CLI reference for -norulesetcompatibility shows a boolean default value

    API Changes

    Deprecated APIs

    For removal
    Internal APIs

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.19.0.zip(58.02 MB)
    pmd-doc-6.19.0.zip(5.52 MB)
    pmd-src-6.19.0.zip(14.13 MB)
  • pmd_releases/6.18.0(Sep 15, 2019)

    15-September-2019 - 6.18.0

    The PMD team is pleased to announce PMD 6.18.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Java 13 Support

    This release of PMD brings support for Java 13. PMD can parse Switch Expressions with the new yield statement and resolve the type of such an expression.

    PMD also parses Text Blocks as String literals.

    Note: The Switch Expressions and Text Blocks are a preview language feature of OpenJDK 13 and are not enabled by default. In order to analyze a project with PMD that uses these language features, you'll need to enable it via the environment variable PMD_JAVA_OPTS and select the new language version 13-preview:

    export PMD_JAVA_OPTS=--enable-preview
    ./run.sh pmd -language java -version 13-preview ...
    

    Note: Support for the extended break statement introduced in Java 12 as a preview language feature will be removed with the next PMD version 6.19.0.

    Full support for Scala

    Thanks to Chris Smith PMD now fully supports Scala. Now rules for analyzing Scala code can be developed in addition to the Copy-Paste-Detection (CPD) functionality. There are no rules yet, so contributions are welcome.

    Additionally Scala support has been upgraded from 2.12.4 to 2.13.

    New rule designer documentation

    The documentation for the rule designer is now available on the main PMD documentation page: Rule Designer Reference. Check it out to learn about the usage and features of the rule designer.

    New rules

    • The Java rule AvoidMessageDigestField (java-bestpractices) detects fields of the type java.security.MessageDigest. Using a message digest instance as a field would need to be synchronized, as it can easily be used by multiple threads. Without synchronization the calculated hash could be entirely wrong. Instead of declaring this as a field and synchronize access to use it from multiple threads, a new instance should be created when needed. This rule is also active when using java's quickstart ruleset.

    • The Apex rule DebugsShouldUseLoggingLevel (apex-bestpractices) detects usages of System.debug() method calls that are used without specifying the log level. Having the log level specified provides a cleaner log, and improves readability of it.

    Modified Rules

    • The Java rule CloseResource (java-errorprone) now ignores by default instances of java.util.stream.Stream. These streams are AutoCloseable, but most streams are backed by collections, arrays, or generating functions, which require no special resource management. However, there are some exceptions: The stream returned by Files::lines(Path) is backed by a actual file and needs to be closed. These instances won't be found by default by the rule anymore.

    Fixed Issues

    • all
      • #1465: [core] Stylesheet pmd-report.xslt fails to display filepath if 'java' in path
      • #1923: [core] Incremental analysis does not work with shortnames
      • #1983: [core] Avoid crashes with analysis cache when classpath references non-existing directories
      • #1990: [core] Incremental analysis mixes XPath rule violations
    • apex
      • #1901: [apex] Expose super type name of UserClass
      • #1942: [apex] Add best practice rule for debug statements in Apex
    • java
      • #1930: [java] Add Java 13 support
    • java-bestpractices
      • #1227: [java] UnusedFormalParameter should explain checkAll better
      • #1862: [java] New rule for MessageDigest.getInstance
      • #1952: [java] UnusedPrivateField not triggering if @Value annotation present
    • java-codestyle
      • #1951: [java] UnnecessaryFullyQualifiedName rule triggered when variable name clashes with package name
    • java-errorprone
      • #1922: [java] CloseResource possible false positive with Streams
      • #1966: [java] CloseResource false positive if Stream is passed as method parameter
      • #1967: [java] CloseResource false positive with late assignment of variable
    • plsql
      • #1933: [plsql] ParseException with cursor declared in anonymous block
      • #1935: [plsql] ParseException with SELECT INTO record defined as global variable
      • #1936: [plslq] ParseException with cursor inside procedure declaration
      • #1946: [plsql] ParseException with using TRIM inside IF statements condition
      • #1947: [plsql] ParseError - SELECT with FOR UPDATE OF
      • #1948: [plsql] ParseException with INSERT INTO using package global variables
      • #1950: [plsql] ParseException with UPDATE and package record variable
      • #1953: [plsql] ParseException with WITH in CURSOR

    API Changes

    Changes to Renderer

    • Each renderer has now a new method Renderer#setUseShortNames which is used for implementing the "shortnames" CLI option. The method is automatically called by PMD, if this CLI option is in use. When rendering filenames to the report, the new helper method AbstractRenderer#determineFileName should be used. This will change the filename to a short name, if the CLI option "shortnames" is used.

      Not adjusting custom renderers will make them render always the full file names and not honoring the CLI option "shortnames".

    Deprecated APIs

    For removal
    Internal APIs

    Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. You can identify them with the @InternalApi annotation. You'll also get a deprecation warning.

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.18.0.zip(57.96 MB)
    pmd-doc-6.18.0.zip(5.51 MB)
    pmd-src-6.18.0.zip(14.26 MB)
  • pmd_releases/6.17.0(Jul 28, 2019)

    28-July-2019 - 6.17.0

    The PMD team is pleased to announce PMD 6.17.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Updated PMD Designer

    This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog. It contains a new feature to edit test cases directly within the designer. Any feedback is highly appreciated.

    Lua support

    Thanks to the contribution from Maikel Steneker, and built on top of the ongoing efforts to fully support Antlr-based languages, PMD now has CPD support for Lua.

    Being based on a proper Antlr grammar, CPD can:

    Modified Rules

    • The Java rule CloseResource (java-errorprone) ignores now by default java.io.ByteArrayInputStream and java.io.CharArrayWriter. Such streams/writers do not need to be closed.

    • The Java rule MissingStaticMethodInNonInstantiatableClass (java-errorprone) has now the new property annotations. When one of the private constructors is annotated with one of the annotations, then the class is not considered non-instantiatable anymore and no violation will be reported. By default, Spring's @Autowired and Java EE's @Inject annotations are recognized.

    Fixed Issues

    • core
      • #1913: [core] "-help" CLI option ends with status code != 0
    • doc
      • #1896: [doc] Error in changelog 6.16.0 due to not properly closed rule tag
      • #1898: [doc] Incorrect code example for DoubleBraceInitialization in documentation on website
      • #1906: [doc] Broken link for adding own CPD languages
      • #1909: [doc] Sample usage example refers to deprecated ruleset "basic.xml" instead of "quickstart.xml"
    • java
      • #1910: [java] ATFD calculation problem
    • java-errorprone
      • #1749: [java] DD False Positive in DataflowAnomalyAnalysis
      • #1832: [java] False positives for MissingStaticMethodInNonInstantiatableClass when DI is used
      • #1921: [java] CloseResource false positive with ByteArrayInputStream
    • java-multithreading
      • #1903: [java] UnsynchronizedStaticFormatter doesn't allow block-level synchronization when using allowMethodLevelSynchronization=true
    • plsql
      • #1902: [pslql] ParseException when parsing (+)
    • xml
      • #1666: [xml] wrong cdata rule description and examples

    External Contributions

    • #1869: [xml] fix #1666 wrong cdata rule description and examples - Artem
    • #1892: [lua] [cpd] Added CPD support for Lua - Maikel Steneker
    • #1905: [java] DataflowAnomalyAnalysis Rule in right order - YoonhoChoi96
    • #1908: [doc] Update ruleset filename from deprecated basic.xml to quickstart.xml - crunsk
    • #1916: [java] Exclude Autowired and Inject for MissingStaticMethodInNonInstantiatableClass - AnthonyKot
    • #1917: [core] Add 'no error' return option, and assign it to the cli when the help command is invoked - Renato Oliveira
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.17.0.zip(46.00 MB)
    pmd-doc-6.17.0.zip(3.60 MB)
    pmd-src-6.17.0.zip(31.76 MB)
  • pmd_releases/6.16.0(Jun 30, 2019)

    30-June-2019 - 6.16.0

    The PMD team is pleased to announce PMD 6.16.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Updated PMD Designer

    This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.

    PLSQL Grammar Updates

    The grammar has been updated to support inline constraints in CREATE TABLE statements. Additionally, the CREATE TABLE statement may now be followed by physical properties and table properties. However, these properties are skipped over during parsing.

    The CREATE VIEW statement now supports subquery views.

    The EXTRACT function can now be parsed correctly. It is used to extract values from a specified datetime field. Also date time literals are parsed now correctly.

    The CASE expression can now be properly used within SELECT statements.

    Table aliases are now supported when specifying columns in INSERT INTO clauses.

    New Rules

    • The Java rule DoubleBraceInitialization (java-bestpractices) detects non static initializers in anonymous classes also known as "double brace initialization". This can be problematic, since a new class file is generated and object holds a strong reference to the surrounding class.

      Note: This rule is also part of the Java quickstart ruleset (rulesets/java/quickstart.xml).

    Modified Rules

    • The Java rule UnusedPrivateField (java-bestpractices) now ignores by default fields, that are annotated with the Lombok experimental annotation @Delegate. This can be customized with the property ignoredAnnotations.

    • The Java rule SingularField (java-design) now ignores by default fields, that are annotated with the Lombok experimental annotation @Delegate. This can be customized with the property ignoredAnnotations.

    • The Java rules UnsynchronizedStaticFormatter and UnsynchronizedStaticDateFormatter (java-multithreading) now prefer synchronized blocks by default. They will raise a violation, if the synchronization is implemented on the method level. To allow the old behavior, the new property allowMethodLevelSynchronization can be enabled.

    • The Java rule UseUtilityClass (java-design) has a new property ignoredAnnotations. By default, classes that are annotated with Lombok's @UtilityClass are ignored now.

    • The Java rule NonStaticInitializer (java-errorprone) does not report non static initializers in anonymous classes anymore. For this use case, there is a new rule now: DoubleBraceInitialization (java-bestpractices).

    • The Java rule CommentDefaultAccessModifier (java-codestyle) was enhanced in the last version 6.15.0 to check also top-level types by default. This created many new violations. Missing the access modifier for top-level types is not so critical, since it only decreases the visibility of the type.

      The default behaviour has been restored. If you want to enable the check for top-level types, you can use the new property checkTopLevelTypes.

    • The Java rule CloseResource (java-errorprone) now by default searches for any unclosed java.lang.AutoCloseable resource. This includes now the standard java.io.*Stream classes. Previously only SQL-related resources were considered by this rule. The types can still be configured via the types property. Some resources do not need to be closed (e.g. ByteArrayOutputStream). These exceptions can be configured via the new property allowedResourceTypes. In order to restore the old behaviour, just remove the type java.lang.AutoCloseable from the types property and keep the remaining SQL-related classes.

    Deprecated Rules

    • The Java rule AvoidFinalLocalVariable (java-codestyle) has been deprecated and will be removed with PMD 7.0.0. The rule is controversial and also contradicts other existing rules such as LocalVariableCouldBeFinal. If the goal is to avoid defining constants in a scope smaller than the class, then the rule AvoidDuplicateLiterals should be used instead.

    Fixed Issues

    • apex
      • #1664: [apex] False positive ApexSharingViolationsRule, unsupported Apex feature
    • java
      • #1848: [java] Local classes should preserve their modifiers
    • java-bestpractices
      • #1703: [java] UnusedPrivateField on member annotated with lombok @Delegate
      • #1845: [java] Regression in MethodReturnsInternalArray not handling enums
      • #1854: [java] Rule to check for double brace initialisation
    • java-codestyle
      • #1612: [java] Deprecate AvoidFinalLocalVariable
      • #1880: [java] CommentDefaultAccessModifier should be configurable for top-level classes
    • java-design
      • #1094: [java] UseUtilityClass should be LombokAware
    • java-errorprone
      • #1000: [java] The rule CloseResource should deal with IO stream as default
      • #1853: [java] False positive for NonStaticInitializer in anonymous class
    • java-multithreading
      • #1814: [java] UnsynchronizedStaticFormatter documentation and implementation wrong
      • #1815: [java] False negative in UnsynchronizedStaticFormatter
    • plsql
      • #1828: [plsql] Parentheses stopped working
      • #1850: [plsql] Parsing errors with INSERT using returning or records and TRIM expression
      • #1873: [plsql] Expression list not working
      • #1878: [pslql] ParseException when parsing USING
      • #1879: [pslql] ParseException when parsing LEFT JOIN

    API Changes

    Deprecated APIs

    Reminder: Please don't use members marked with the annotation InternalApi, as they will likely be removed, hidden, or otherwise intentionally broken with 7.0.0.

    In ASTs

    As part of the changes we'd like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. The following usages are now deprecated in the Java AST (with other languages to come):

    • Manual instantiation of nodes. Constructors of node classes are deprecated and marked InternalApi. Nodes should only be obtained from the parser, which for rules, means that never need to instantiate node themselves. Those constructors will be made package private with 7.0.0.
    • Subclassing of abstract node classes, or usage of their type. Version 7.0.0 will bring a new set of abstractions that will be public API, but the base classes are and will stay internal. You should not couple your code to them.
      • In the meantime you should use interfaces like JavaNode or Node, or the other published interfaces in this package, to refer to nodes generically.
      • Concrete node classes will be made final with 7.0.0.
    • Setters found in any node class or interface. Rules should consider the AST immutable. We will make those setters package private with 7.0.0.

    Please look at net.sourceforge.pmd.lang.java.ast to find out the full list of deprecations.

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.16.0.zip(45.82 MB)
    pmd-doc-6.16.0.zip(3.60 MB)
    pmd-src-6.16.0.zip(29.99 MB)
  • pmd_releases/6.15.0(May 26, 2019)

    26-May-2019 - 6.15.0

    The PMD team is pleased to announce PMD 6.15.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Enhanced Matlab support

    Thanks to the contributions from Maikel Steneker CPD for Matlab can now parse Matlab programs which use the question mark operator to specify access to class members:

    classdef Class1
    properties (SetAccess = ?Class2)
    

    CPD also understands now double quoted strings, which are supported since version R2017a of Matlab:

    str = "This is a string"
    

    Enhanced C++ support

    CPD now supports digit separators in C++ (language module "cpp"). This is a C++14 feature.

    Example: auto integer_literal = 1'000'000;

    The single quotes can be used to add some structure to large numbers.

    CPD also parses raw string literals now correctly (see #1784).

    New Rules

    • The new Apex rule FieldNamingConventions (apex-codestyle) checks the naming conventions for field declarations. By default this rule uses the standard Apex naming convention (Camel case), but it can be configured through properties.

    • The new Apex rule FormalParameterNamingConventions (apex-codestyle) checks the naming conventions for formal parameters of methods. By default this rule uses the standard Apex naming convention (Camel case), but it can be configured through properties.

    • The new Apex rule LocalVariableNamingConventions (apex-codestyle) checks the naming conventions for local variable declarations. By default this rule uses the standard Apex naming convention (Camel case), but it can be configured through properties.

    • The new Apex rule PropertyNamingConventions (apex-codestyle) checks the naming conventions for property declarations. By default this rule uses the standard Apex naming convention (Camel case), but it can be configured through properties.

    • The new Java rule UseShortArrayInitializer (java-codestyle) searches for array initialization expressions, which can be written shorter.

    Modified Rules

    • The Apex rule ClassNamingConventions (apex-codestyle) can now be configured using various properties for the specific kind of type declarations (e.g. class, interface, enum). As before, this rule uses by default the standard Apex naming convention (Pascal case).

    • The Apex rule MethodNamingConventions (apex-codestyle) can now be configured using various properties to differenciate e.g. static methods and test methods. As before, this rule uses by default the standard Apex naming convention (Camel case).

    • The Java rule FieldNamingConventions (java-codestyle) now by default ignores the field serialPersistentFields. Since this is a field which needs to have this special name, no field naming conventions can be applied here. It is excluded the same way like serialVersionUID via the property exclusions.

    • The Java rule CommentRequired (java-documentation) has a new property serialPersistentFieldsCommentRequired with the default value "Ignored". This means that from now on comments for the field serialPersistentFields are not required anymore. You can change the property to restore the old behavior.

    • The Java rule ProperLogger (java-errorprone) has two new properties to configure the logger class (e.g. "org.slf4j.Logger") and the logger name of the special case, when the logger is not static. The name of the static logger variable was already configurable. The new property "loggerClass" allows to use this rule for different logging frameworks. This rule covers all the cases of the now deprecated rule LoggerIsNotStaticFinal.

    • The Java rule CommentDefaultAccessModifier (java-codestyle) now reports also missing comments for top-level classes and annotations, that are package-private.

    Deprecated Rules

    Fixed Issues

    • apex
      • #1321: [apex] Should VariableNamingConventions require properties to start with a lowercase letter?
      • #1783: [apex] comments on constructor not recognized when the Class has inner class
    • cpp
      • #1784: [cpp] Improve support for raw string literals
    • dart
      • #1809: [dart] [cpd] Parse error with escape sequences
    • java
      • #1842: [java] Annotated module declarations cause parse error
    • java-bestpractices
      • #1738: [java] MethodReturnsInternalArray does not work in inner classes
    • java-codestyle
      • #1495: [java] Rule to detect overly verbose array initializiation
      • #1684: [java] Properly whitelist serialPersistentFields
      • #1804: [java] NPE in UnnecessaryLocalBeforeReturnRule
    • python
      • #1810: [python] [cpd] Parse error when using Python 2 backticks
    • matlab
      • #1830: [matlab] [cpd] Parse error with comments
      • #1793: [java] CommentDefaultAccessModifier not working for classes

    API Changes

    Deprecated APIs

    For removal

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.15.0.zip(45.65 MB)
    pmd-doc-6.15.0.zip(3.59 MB)
    pmd-src-6.15.0.zip(29.54 MB)
  • pmd_releases/6.14.0(Apr 28, 2019)

    28-April-2019 - 6.14.0

    The PMD team is pleased to announce PMD 6.14.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Dart support

    Thanks to the contribution from Maikel Steneker, and built on top of the ongoing efforts to fully support Antlr-based languages, PMD now has CPD support for Dart.

    Being based on a proper Antlr grammar, CPD can:

    Updated PMD Designer

    This PMD release ships a new version of the pmd-designer. For the changes, see PMD Designer Changelog.

    Modified Rules

    • The Java rule AssignmentToNonFinalStatic (java-errorprone) will now report on each assignment made within a constructor rather than on the field declaration. This makes it easier for developers to find the offending statements.

    • The Java rule NoPackage (java-codestyle) will now report additionally enums and annotations that do not have a package declaration.

    Fixed Issues

    • all
      • #1515: [core] Module pmd-lang-test is missing javadoc artifact
      • #1788: [cpd] [core] Use better ClassLoader for ServiceLoader in LanguageFactory
      • #1794: [core] Ruleset Compatibility fails with excluding rules
    • go
      • #1751: [go] Parsing errors encountered with escaped backslash
    • java
      • #1532: [java] NPE with incomplete auxclasspath
      • #1691: [java] Possible Data Race in JavaTypeDefinitionSimple.getGenericType
      • #1729: [java] JavaRuleViolation loses information in className field when class has package-private access level
    • java-bestpractices
      • #1190: [java] UnusedLocalVariable/UnusedPrivateField false-positive
      • #1720: [java] UnusedImports false positive for Javadoc link with array type
    • java-codestyle
      • #1755: [java] False negative in UnnecessaryLocalBeforeReturn when splitting statements across multiple lines
      • #1782: [java] NoPackage: False Negative for enums
    • java-design
      • #1760: [java] UseObjectForClearerAPI flags private methods

    API Changes

    No changes.

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.14.0.zip(45.63 MB)
    pmd-doc-6.14.0.zip(3.59 MB)
    pmd-src-6.14.0.zip(29.13 MB)
  • pmd_releases/6.13.0(Mar 31, 2019)

    31-March-2019 - 6.13.0

    The PMD team is pleased to announce PMD 6.13.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Call For Logo

    We are still searching for a new logo for PMD for the next major release.

    Learn more about how to participate on github issue 1663.

    Java 12 Support

    This release of PMD brings support for Java 12. PMD can parse the new Switch Expressions and resolve the type of such an expression.

    Note: The Switch Expressions are a preview language feature of OpenJDK 12 and are not enabled by default. In order to analyze a project with PMD that uses these language features, you'll need to enable it via the new environment variable PMD_JAVA_OPTS:

    export PMD_JAVA_OPTS=--enable-preview
    ./run.sh pmd ...
    

    Quickstart Ruleset for Apex

    PMD provides now a quickstart ruleset for Salesforce.com Apex, which you can use as a base ruleset to get your custom ruleset started. You can reference it with rulesets/apex/quickstart.xml. You are strongly encouraged to create your own ruleset though.

    The quickstart ruleset has the intention, to be useful out-of-the-box for many projects. Therefore it references only rules, that are most likely to apply everywhere.

    Any feedback would be greatly appreciated.

    PMD Designer

    The rule designer's codebase has been moved out of the main repository and will be developed at pmd/pmd-designer from now on. The maven coordinates will stay the same for the time being. The designer will still be shipped with PMD's binaries.

    Improved Apex Support

    • Many AST nodes now expose more information which makes it easier to write XPath-based rules for Apex. Here are some examples:
      • Annotation[@Resolved = false()] finds unsupported annotations.
      • AnnotationParameter[@Name='RestResource'][@Value='/myurl'] gives access to annotation parameters.
      • CatchBlockStatement[@ExceptionType='Exception'][@VariableName='e'] finds catch block for specific exception types.
      • Field[@Type='String'] find all String fields, Field[string-length(@Name) < 5] finds all fields with short names and Field[@Value='a'] find alls fields, that are initialized with a specific value.
      • LiteralExpression[@String = true()] finds all String literals. There are attributes for each type: @Boolean, @Integer, @Double, @Long, @Decimal, @Null.
      • Method[@Constructor = true()] selects all constructors. Method[@ReturnType = 'String'] selects all methods that return a String.
      • The ModifierNode node has a couple of attributes to check for the existence of specific modifiers: @Test, @TestOrTestSetup, @WithSharing, @WithoutSharing, @InheritedSharing, @WebService, @Global, @Override.
      • Many nodes now expose their type. E.g. with Parameter[@Type='Integer'] you can find all method parameters of type Integer. The same attribute Type exists as well for: NewObjectExpression, Property, VariableDeclaration.
      • VariableExpression[@Image='i'] finds all variable usages of the variable "i".

    New Rules

    • The new Java rule AvoidUncheckedExceptionsInSignatures (java-design) finds methods or constructors that declare unchecked exceptions in their throws clause. This forces the caller to handle the exception, even though it is a runtime exception.

    • The new Java rule DetachedTestCase (java-errorprone) searches for public methods in test classes, which are not annotated with @Test. These methods might be test cases where the annotation has been forgotten. Because of that those test cases are never executed.

    • The new Java rule WhileLoopWithLiteralBoolean (java-bestpractices) finds Do-While-Loops and While-Loops that can be simplified since they use simply true or false as their loop condition.

    • The new Apex rule ApexAssertionsShouldIncludeMessage (apex-bestpractices) searches for assertions in unit tests and checks, whether they use a message argument.

    • The new Apex rule ApexUnitTestMethodShouldHaveIsTestAnnotation (apex-bestpractices) searches for methods in test classes, which are missing the @IsTest annotation.

    • The new PLSQL rule AvoidTabCharacter (plsql-codestyle) checks, that there are no tab characters ("\t") in the source file.

    • The new PLSQL rule LineLength (plsql-codestyle) helps to enforce a maximum line length.

    Fixed Issues

    • doc
      • #1721: [doc] Documentation provides an invalid property configuration example
    • java
      • #1537: [java] Java 12 support
    • java-bestpractices
      • #1701: [java] UseTryWithResources does not handle multiple argument close methods
    • java-codestyle
      • #1527: [java] UseUnderscoresInNumericLiterals false positive on floating point numbers
      • #1674: [java] documentation of CommentDefaultAccessModifier is wrong
    • java-errorprone
      • #1570: [java] AvoidDuplicateLiterals warning about deprecated separator property when not used
    • plsql
      • #1510: [plsql] Support XMLTABLE functions
      • #1716: [plsql] Support access to whole plsql code
      • #1731: [pslql] ParseException when parsing ELSIF
      • #1733: [plsql] % not supported in "TestSearch%notfound"
      • #1734: [plsql] TooManyMethods false-negative
      • #1735: [plsql] False-negatives for TO_DATE_TO_CHAR, TO_DATEWithoutDateFormat, TO_TIMESTAMPWithoutDateFormat

    API Changes

    Command Line Interface

    The start scripts run.sh, pmd.bat and cpd.bat support the new environment variable PMD_JAVA_OPTS. This can be used to set arbitrary JVM options for running PMD, such as memory settings (e.g. PMD_JAVA_OPTS=-Xmx512m) or enable preview language features (e.g. PMD_JAVA_OPTS=--enable-preview).

    The previously available variables such as OPTS or HEAPSIZE are deprecated and will be removed with PMD 7.0.0.

    Deprecated API

    • CodeClimateRule is deprecated in 7.0.0 because it was unused for 2 years and created an unwanted dependency. Properties "cc_categories", "cc_remediation_points_multiplier", "cc_block_highlighting" will also be removed. See #1702 for more.

    • The Apex ruleset rulesets/apex/ruleset.xml has been deprecated and will be removed in 7.0.0. Please use the new quickstart ruleset rulesets/apex/quickstart.xml instead.

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.13.0.zip(43.96 MB)
    pmd-doc-6.13.0.zip(3.59 MB)
    pmd-src-6.13.0.zip(31.55 MB)
  • pmd_releases/6.12.0(Feb 24, 2019)

    24-February-2019 - 6.12.0

    The PMD team is pleased to announce PMD 6.12.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Call For Logo

    PMD’s logo was great for a long time. But now we want to take the opportunity with the next major release to change our logo in order to use a more "politically correct" one.

    Learn more about how to participate on github issue 1663.

    CPD Suppression for Antlr-based languages

    ITBA students Matías Fraga, Tomi De Lucca and Lucas Soncini keep working on bringing full Antlr support to PMD. For this release, they have implemented token filtering in an equivalent way as we did for JavaCC languages, adding support for CPD suppressions through CPD-OFF and CPD-ON comments for all Antlr-based languages.

    This means, you can now ignore arbitrary blocks of code on:

    • Go
    • Kotlin
    • Swift

    Simply start the suppression with any comment (single or multiline) containing CPD-OFF, and resume again with a comment containing CPD-ON.

    More information is available in the user documentation.

    PL/SQL Grammar improvements

    • In this release, many more parser bugs in our PL/SQL support have been fixed. This adds more complete support for UPDATE statements and subqueries and hierarchical queries in SELECT statements.
    • Support for analytic functions such as LISTAGG has been added.
    • Conditions in WHERE clauses support now REGEX_LIKE and multiset conditions.

    New Rules

    • The new Java rule UseTryWithResources (java-bestpractices) searches for try-blocks, that could be changed to a try-with-resources statement. This statement ensures that each resource is closed at the end of the statement and is available since Java 7.

    Modified Rules

    • The Apex rule MethodNamingConventions (apex-codestyle) has a new property skipTestMethodUnderscores, which is by default disabled. The new property allows for ignoring all test methods, either using the testMethod modifier or simply annotating them @isTest.

    Fixed Issues

    • all
      • #1462: [core] Failed build on Windows with source zip archive
      • #1559: [core] CPD: Lexical error in file (no file name provided)
      • #1671: [doc] Wrong escaping in suppressing warnings for nopmd-comment
      • #1693: [ui] Improved error reporting for the designer
    • java-bestpractices
      • #808: [java] AccessorMethodGeneration false positives with compile time constants
      • #1405: [java] New Rule: UseTryWithResources - Replace close and IOUtils.closeQuietly with try-with-resources
      • #1555: [java] UnusedImports false positive for method parameter type in @see Javadoc
    • java-codestyle
      • #1543: [java] LinguisticNaming should ignore overriden methods
      • #1547: [java] AtLeastOneConstructorRule: false-positive with lombok.AllArgsConstructor
      • #1624: [java] UseDiamondOperator false positive with var initializer
    • java-design
      • #1641: [java] False-positive with Lombok and inner classes
    • java-errorprone
      • #780: [java] BeanMembersShouldSerializeRule does not recognize lombok accessors
    • java-multithreading
      • #1633: [java] UnsynchronizedStaticFormatter reports commons lang FastDateFormat
    • java-performance
      • #1632: [java] ConsecutiveLiteralAppends false positive over catch
    • plsql
      • #1587: [plsql] ParseException with EXISTS
      • #1589: [plsql] ParseException with subqueries in WHERE clause
      • #1590: [plsql] ParseException when using hierarchical query clause
      • #1656: [plsql] ParseException with analytic functions, trim and subqueries
    • designer
      • #1679: [ui] No default language version selected

    API Changes

    No changes.

    External Contributions

    • #1623: [java] Fix lombok.AllArgsConstructor support - Bobby Wertman
    • #1625: [java] UnusedImports false positive for method parameter type in @see Javadoc - Shubham
    • #1628: [java] LinguisticNaming should ignore overriden methods - Shubham
    • #1634: [java] BeanMembersShouldSerializeRule does not recognize lombok accessors - Shubham
    • #1635: [java] UnsynchronizedStaticFormatter reports commons lang FastDateFormat - Shubham
    • #1637: [java] Compile time constants initialized by literals avoided by AccessorMethodGenerationRule - Shubham
    • #1640: [java] Update instead of override classHasLombokAnnotation flag - Phokham Nonava
    • #1644: [apex] Add property to allow apex test methods to contain underscores - Tom
    • #1645: [java] ConsecutiveLiteralAppends false positive - Shubham
    • #1646: [java] UseDiamondOperator doesn't work with var - Shubham
    • #1654: [core] Antlr token filter - Tomi De Lucca
    • #1655: [kotlin] Kotlin tokenizer refactor - Lucas Soncini
    • #1686: [doc] Replaced wrong escaping with ">" - Himanshu Pandey
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.12.0.zip(43.94 MB)
    pmd-doc-6.12.0.zip(3.57 MB)
    pmd-src-6.12.0.zip(30.88 MB)
  • pmd_releases/6.11.0(Jan 27, 2019)

    27-January-2019 - 6.11.0

    The PMD team is pleased to announce PMD 6.11.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Updated Apex Support

    • The Apex language support has been bumped to version 45 (Spring '19). All new language features are now properly parsed and processed.
    • Many nodes now expose more informations, such as the operator for BooleanExpressions. This makes these operators consumable by XPath rules, e.g. //BooleanExpression[@Operator='&&'].

    PL/SQL Grammar improvements

    • In this release, many parser bugs in our PL/SQL support have been fixed. This adds e.g. support for table collection expressions (SELECT * FROM TABLE(expr)).
    • Support for parsing insert statements has been added.
    • More improvements are planned for the next release of PMD.

    New Rules

    • The new Java rule UnsynchronizedStaticFormatter (java-multithreading) detects unsynchronized usages of static java.text.Format instances. This rule is a more generic replacement of the rule UnsynchronizedStaticDateFormatter which focused just on DateFormat.

    • The new Java rule ForLoopVariableCount (java-bestpractices) checks for the number of control variables in a for-loop. Having a lot of control variables makes it harder to understand what the loop does. The maximum allowed number of variables is by default 1 and can be configured by a property.

    • The new Java rule AvoidReassigningLoopVariables (java-bestpractices) searches for loop variables that are reassigned. Changing the loop variables additionally to the loop itself can lead to hard-to-find bugs.

    • The new Java rule UseDiamondOperator (java-codestyle) looks for constructor calls with explicit type parameters. Since Java 1.7, these type parameters are not necessary anymore, as they can be inferred now.

    Modified Rules

    • The Java rule LocalVariableCouldBeFinal (java-codestyle) has a new property ignoreForEachDecl, which is by default disabled. The new property allows for ignoring non-final loop variables in a for-each statement.

    Deprecated Rules

    Fixed Issues

    • core
      • #1196: [core] CPD results not consistent between runs
      • #1496 [core] Refactor metrics to be dealt with generically from pmd-core
    • apex
      • #1542: [apex] Include the documentation category
      • #1546: [apex] PMD parsing exception for Apex classes using 'inherited sharing' keyword
      • #1568: [apex] AST node attribute @Image not usable / always null in XPath rule / Designer
    • java
      • #1556: [java] Default methods should not be considered abstract
      • #1578: [java] Private field is detected as public inside nested classes in interfaces
    • java-bestpractices
      • #658: [java] OneDeclarationPerLine: False positive for loops
      • #1518: [java] New rule: AvoidReassigningLoopVariable
      • #1519: [java] New rule: ForLoopVariableCount
    • java-codestyle
      • #1513: [java] LocalVariableCouldBeFinal: allow excluding the variable in a for-each loop
      • #1517: [java] New Rule: UseDiamondOperator
    • java-errorprone
      • #1035: [java] ReturnFromFinallyBlock: False positive on lambda expression in finally block
      • #1549: [java] NPE in PMD 6.8.0 InvalidSlf4jMessageFormat
    • java-multithreading
      • #1533: [java] New rule: UnsynchronizedStaticFormatter
    • plsql
      • #1507: [plsql] Parse Exception when using '||' operator in where clause
      • #1508: [plsql] Parse Exception when using SELECT COUNT(*)
      • #1509: [plsql] Parse Exception with OUTER/INNER Joins
      • #1511: [plsql] Parse Exception with IS NOT NULL
      • #1526: [plsql] ParseException when using TableCollectionExpression
      • #1583: [plsql] Update Set Clause should allow multiple columns
      • #1586: [plsql] Parse Exception when functions are used with LIKE
      • #1588: [plsql] Parse Exception with function calls in WHERE clause

    API Changes

    External Contributions

    • #1503: [java] Fix for ReturnFromFinallyBlock false-positives - RishabhDeep Singh
    • #1514: [java] LocalVariableCouldBeFinal: allow excluding the variable in a for-each loop - Kris Scheibe
    • #1516: [java] OneDeclarationPerLine: Don't report multiple variables in a for statement. - Kris Scheibe
    • #1520: [java] New rule: ForLoopVariableCount: check the number of control variables in a for loop - Kris Scheibe
    • #1521: [java] Upgrade to ASM7 for JDK 11 support - Mark Pritchard
    • #1530: [java] New rule: AvoidReassigningLoopVariables - Kris Scheibe
    • #1534: [java] This is the change regarding the usediamondoperator #1517 - hemanshu070
    • #1545: [doc] fixing dead links + tool to check for dead links automatically - Kris Scheibe
    • #1551: [java] InvalidSlf4jMessageFormatRule should not throw NPE for enums - Robbie Martinus
    • #1552: [core] Upgrading Google Gson from 2.5 to 2.8.5 - Thunderforge
    • #1553: [core] Upgrading System Rules dependency from 1.8.0 to 1.19.0 - Thunderforge
    • #1554: [plsql] updates should allow for multiple statements - tashiscool
    • #1584: [core] Fixes 1196: inconsistencies of clones returned by different CPD executions for the same files - Bruno Ferreira
    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.11.0.zip(43.90 MB)
    pmd-doc-6.11.0.zip(3.57 MB)
    pmd-src-6.11.0.zip(30.18 MB)
  • pmd_releases/6.10.0(Dec 9, 2018)

    09-December-2018 - 6.10.0

    The PMD team is pleased to announce PMD 6.10.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Kotlin support for CPD

    Thanks to Maikel Steneker, CPD now supports Kotlin. This means, you can use CPD to find duplicated code in your Kotlin projects.

    New Rules

    • The new Java rule UseUnderscoresInNumericLiterals (java-codestyle) verifies that numeric literals over a given length (4 chars by default, but configurable) are using underscores every 3 digits for readability. The rule only applies to Java 7+ codebases.

    Modified Rules

    Fixed Issues

    • all
      • #1284: [doc] Keep record of every currently deprecated API
      • #1318: [test] Kotlin DSL to ease test writing
      • #1328: [ci] Building docs for release fails
      • #1341: [doc] Documentation Error with Regex Properties
      • #1468: [doc] Missing escaping leads to XSS
      • #1471: [core] XMLRenderer: ProcessingErrors from exceptions without a message missing
      • #1477: [core] Analysis cache fails with wildcard classpath entries
    • java
      • #1460: [java] Intermittent PMD failure : PMD processing errors while no violations reported
    • java-bestpractices
      • #647: [java] JUnitTestsShouldIncludeAssertRule should support this.exception as well as just exception
      • #1435: [java] JUnitTestsShouldIncludeAssert: Support AssertJ soft assertions
    • java-codestyle
      • #1232: [java] Detector for large numbers not separated by _
      • #1372: [java] false positive for UselessQualifiedThis
      • #1440: [java] CommentDefaultAccessModifierRule shows incorrect message
    • java-design
      • #1151: [java] ImmutableField false positive with multiple constructors
      • #1483: [java] Cyclo metric should count conditions of for statements correctly
    • java-errorprone
      • #1512: [java] InvalidSlf4jMessageFormatRule causes NPE in lambda and static blocks
    • plsql
      • #1454: [plsql] ParseException for IF/CASE statement with >=, <=, !=

    API Changes

    Properties framework

    The properties framework is about to get a lifting, and for that reason, we need to deprecate a lot of APIs to remove them in 7.0.0. The proposed changes to the API are described on the wiki

    Changes to how you define properties

    Here's an example:

    // Before 7.0.0, these are equivalent:
    IntegerProperty myProperty = new IntegerProperty("score", "Top score value", 1, 100, 40, 3.0f);
    IntegerProperty myProperty = IntegerProperty.named("score").desc("Top score value").range(1, 100).defaultValue(40).uiOrder(3.0f);
    
    // They both map to the following in 7.0.0
    PropertyDescriptor<Integer> myProperty = PropertyFactory.intProperty("score").desc("Top score value").require(inRange(1, 100)).defaultValue(40);
    

    You're highly encouraged to migrate to using this new API as soon as possible, to ease your migration to 7.0.0.

    Architectural simplifications
    Changes to the PropertyDescriptor interface
    • preferredRowCount is deprecated with no intended replacement. It was never implemented, and does not belong in this interface. The methods uiOrder and compareTo(PropertyDescriptor) are deprecated for the same reason. These methods mix presentation logic with business logic and are not necessary for PropertyDescriptors to work. PropertyDescriptor will not extend Comparable<PropertyDescriptor> anymore come 7.0.0.
    • The method propertyErrorFor is deprecated and will be removed with no intended replacement. It's really just a shortcut for prop.errorFor(rule.getProperty(prop)).
    • TvalueFrom(String) and StringasDelimitedString(T) are deprecated and will be removed. These were used to serialize and deserialize properties to/from a string, but 7.0.0 will introduce a more flexible XML syntax which will make them obsolete.
    • isMultiValue and type are deprecated and won't be replaced. The new XML syntax will remove the need for a divide between multi- and single-value properties, and will allow arbitrary types to be represented. Since arbitrary types may be represented, type will become obsolete as it can't represent generic types, which will nevertheless be representable with the XML syntax. It was only used for documentation, but a new way to document these properties exhaustively will be added with 7.0.0.
    • errorFor is deprecated as its return type will be changed to Optional<String> with the shift to Java 8.

    Deprecated APIs

    For internalization
    For removal

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.10.0.zip(42.26 MB)
    pmd-doc-6.10.0.zip(3.56 MB)
    pmd-src-6.10.0.zip(27.16 MB)
  • pmd_releases/6.9.0(Oct 28, 2018)

    28-October-2018 - 6.9.0

    The PMD team is pleased to announce PMD 6.9.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Improved Golang CPD Support

    Thanks to the work of ITBA students Matías Fraga, Tomi De Lucca and Lucas Soncini, Golang is now backed by a proper Antlr Grammar. This means CPD is now better at detecting duplicates, as comments are recognized as such and ignored.

    New Rules

    • The new PLSQL rule CodeFormat (plsql-codestyle) verifies that PLSQL code is properly formatted. It checks e.g. for correct indentation in select statements and verifies that each parameter is defined on a separate line.

    Fixed Issues

    • all
      • #649: [core] Exclude specific files from command line
      • #1272: [core] Could not find or load main class when using symlinked run.sh
      • #1377: [core] LanguageRegistry uses default class loader when invoking ServiceLocator
      • #1394: [doc] How to configure "-cache "
      • #1412: [doc] Broken link to adding new cpd language documentation
    • apex
      • #1396: [apex] ClassCastException caused by Javadoc
    • java
      • #1330: [java] PMD crashes with java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/xml/ws/Service
    • java-bestpractices
      • #1202: [java] GuardLogStatement: "There is log block not surrounded by if" doesn't sound right
      • #1209: [java] UnusedImports false positive for static import with package-private method usage
      • #1343: [java] Update CommentDefaultAccessModifierRule to extend AbstractIgnoredAnnotationRule
      • #1365: [java] JUnitTestsShouldIncludeAssert false positive
      • #1404: [java] UnusedImports false positive with static ondemand import with method call
    • java-codestyle
      • #1199: [java] UnnecessaryFullyQualifiedName doesn't flag same package FQCNs
      • #1356: [java] UnnecessaryModifier wrong message public->static
    • java-design
      • #1369: [java] Processing error (ClassCastException) if a TYPE_USE annotation is used on a base class in the "extends" clause
    • jsp
      • #1402: [jsp] JspTokenManager has a problem about jsp scriptlet
    • documentation
      • #1349: [doc] Provide some explanation for WHY duplicate code is bad, like mutations

    API Changes

    • PMD has a new CLI option -ignorelist. With that, you can provide a file containing a comma-delimit list of files, that should be excluded during analysis. The ignorelist is applied after the files have been selected via -dir or -filelist, which means, if the file is in both lists, then it will be ignored. Note: there is no corresponding option for the Ant task, since the feature is already available via Ant's FileSet include/exclude filters.

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.9.0.zip(42.18 MB)
    pmd-doc-6.9.0.zip(3.53 MB)
    pmd-src-6.9.0.zip(27.44 MB)
  • pmd_releases/6.8.0(Sep 30, 2018)

    30-September-2018 - 6.8.0

    The PMD team is pleased to announce PMD 6.8.0.

    This is a minor release.

    Table Of Contents

    New and noteworthy

    Drawing a line between private and public API

    Until now, all released public members and types were implicitly considered part of PMD's public API, including inheritance-specific members (protected members, abstract methods). We have maintained those APIs with the goal to preserve full binary compatibility between minor releases, only breaking those APIs infrequently, for major releases.

    In order to allow PMD to move forward at a faster pace, this implicit contract will be invalidated with PMD 7.0.0. We now introduce more fine-grained distinctions between the type of compatibility support we guarantee for our libraries, and ways to make them explicit to clients of PMD.

    .internal packages and @InternalApi annotation

    Internal API is meant for use only by the main PMD codebase. Internal types and methods may be modified in any way, or even removed, at any time.

    Any API in a package that contains an .internal segment is considered internal. The @InternalApi annotation will be used for APIs that have to live outside of these packages, e.g. methods of a public type that shouldn't be used outside of PMD (again, these can be removed anytime).

    @ReservedSubclassing

    Types marked with the @ReservedSubclassing annotation are only meant to be subclassed by classes within PMD. As such, we may add new abstract methods, or remove protected methods, at any time. All published public members remain supported. The annotation is not inherited, which means a reserved interface doesn't prevent its implementors to be subclassed.

    @Experimental

    APIs marked with the @Experimental annotation at the class or method level are subject to change. They can be modified in any way, or even removed, at any time. You should not use or rely on them in any production code. They are purely to allow broad testing and feedback.

    @Deprecated

    APIs marked with the @Deprecated annotation at the class or method level will remain supported until the next major release but it is recommended to stop using them.

    The transition

    All currently supported APIs will remain so until 7.0.0. All APIs that are to be moved to .internal packages or hidden will be tagged @InternalApi before that major release, and the breaking API changes will be performed in 7.0.0.

    Quickstart Ruleset

    PMD 6.8.0 provides a first quickstart ruleset for Java, which you can use as a base ruleset to get your custom ruleset started. You can reference it with rulesets/java/quickstart.xml. You are strongly encouraged to create your own ruleset though.

    The quickstart ruleset has the intention, to be useful out-of-the-box for many projects. Therefore it references only rules, that are most likely to apply everywhere.

    Any feedback would be greatly appreciated.

    New Rules

    • The new Apex rule ApexDoc (apex-documentation) enforces the inclusion of ApexDoc on classes, interfaces, properties and methods; as well as some sanity rules for such docs (no missing parameters, parameters' order, and return value). By default, method overrides and test classes are allowed to not include ApexDoc.

    Modified Rules

    • The rule MissingSerialVersionUID (java-errorprone) has been modified in order to recognize also missing serialVersionUID fields in abstract classes, if they are serializable. Each individual class in the inheritance chain needs an own serialVersionUID field. See also Should an abstract class have a serialVersionUID. This change might lead to additional violations in existing code bases.

    PLSQL

    The grammar for PLSQL has been revamped in order to fully parse SELECT INTO, UPDATE, and DELETE statements. Previously such statements have been simply skipped ahead, now PMD is parsing them, giving access to the individual parts of a SELECT-statement, such as the Where-Clause. This might produce new parsing errors where PMD previously could successfully parse PLSQL code. If this happens, please report a new issue to get this problem fixed.

    Fixed Issues

    • apex-bestpractices
      • #1348: [apex] AvoidGlobalModifierRule gives warning even when its a webservice - false positive
    • java-codestyle
      • #1329: [java] FieldNamingConventions: false positive in serializable class with serialVersionUID
      • #1334: [java] LinguisticNaming should support AtomicBooleans
    • java-errorprone
      • #1350: [java] MissingSerialVersionUID false-positive on interfaces
      • #1352: [java] MissingSerialVersionUID false-negative with abstract classes
    • java-performance
      • #1325: [java] False positive in ConsecutiveLiteralAppends
    • plsql
      • #1279: [plsql] Support for SELECT INTO

    API Changes

    • A couple of methods and fields in net.sourceforge.pmd.properties.AbstractPropertySource have been deprecated, as they are replaced by already existing functionality or expose internal implementation details: propertyDescriptors, propertyValuesByDescriptor, copyPropertyDescriptors(), copyPropertyValues(), ignoredProperties(), usesDefaultValues(), useDefaultValueFor().

    • Some methods in net.sourceforge.pmd.properties.PropertySource have been deprecated as well: usesDefaultValues(), useDefaultValueFor(), ignoredProperties().

    • The class net.sourceforge.pmd.lang.rule.AbstractDelegateRule has been deprecated and will be removed with PMD 7.0.0. It is internally only in use by RuleReference.

    • The default constructor of net.sourceforge.pmd.lang.rule.RuleReference has been deprecated and will be removed with PMD 7.0.0. RuleReferences should only be created by providing a Rule and a RuleSetReference. Furthermore the following methods are deprecated: setRuleReference(), hasOverriddenProperty(), usesDefaultValues(), useDefaultValueFor().

    External Contributions

    Source code(tar.gz)
    Source code(zip)
    pmd-bin-6.8.0.zip(42.00 MB)
    pmd-doc-6.8.0.zip(3.53 MB)
    pmd-src-6.8.0.zip(11.20 MB)
An extensible multilanguage static code analyzer.

PMD About PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and

PMD 3.5k Jul 20, 2021
:coffee: SonarSource Static Analyzer for Java Code Quality and Security

Code Quality and Security for Java This SonarSource project is a code analyzer for Java projects. Information about the analysis of Java features is a

SonarSource 801 Jul 27, 2021
Tackle Data-intensive Validity Analyzer

Tackle-DiVA (Data-intensive Validity Analyzer) Tackle-DiVA is a command-line tool for data-centric application analysis. It imports a set of target ap

Konveyor 7 Jul 13, 2021
A static analyzer for Java, C, C++, and Objective-C

Infer Infer is a static analysis tool for Java, C++, Objective-C, and C. Infer is written in OCaml. Installation Read our Getting Started page for det

Facebook 12.4k Jul 27, 2021
A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead

NullAway: Fast Annotation-Based Null Checking for Java NullAway is a tool to help eliminate NullPointerExceptions (NPEs) in your Java code. To use Nul

Uber Open Source 3k Jul 26, 2021
SpotBugs is FindBugs' successor. A tool for static analysis to look for bugs in Java code.

SpotBugs is the spiritual successor of FindBugs, carrying on from the point where it left off with support of its community. SpotBugs is licensed unde

null 2.4k Jul 23, 2021
Catch common Java mistakes as compile-time errors

Error Prone Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time. public class ShortSet { public

Google 5.7k Jul 27, 2021
Sourcetrail - free and open-source interactive source explorer

Sourcetrail Sourcetrail is a free and open-source cross-platform source explorer that helps you get productive on unfamiliar source code. Windows: Lin

Coati Software 11.7k Jul 28, 2021
Inria 1.2k Jul 27, 2021
⚡️Lightning-fast linter for .env files. Written in Rust 🦀

⚡️ Lightning-fast linter for .env files. Written in Rust ?? Dotenv-linter can check / fix / compare .env files for problems that may cause the applica

null 1.1k Jul 28, 2021
Continuous Inspection

SonarQube Continuous Inspection SonarQube provides the capability to not only show health of an application but also to highlight issues newly introdu

SonarSource 5.9k Jul 24, 2021
A free injection hacked client for Minecraft using Java-agents

Swift Swift is a free and open-source injection hacked client base for Minecraft using Java-agents. Issues If you notice any bugs, you can let us know

static final 16 Jul 1, 2021
Astra: a Java tool for analysing and refactoring Java source code

What is Astra? Astra is a Java tool for analysing and refactoring Java source code. For example: "References to type A should instead reference type B

Alfa 33 Jul 23, 2021