GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] ApexSharingViolations does not correlate sharing settings with class that contains data access · Issue #2774 · pmd/pmd

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

New issue
Copy link
New issue
Copy link
Closed
#2791
Closed
[apex] ApexSharingViolations does not correlate sharing settings with class that contains data access#2774
#2791
Copy link
Assignees
jbartolotta-sfdc
Labels
a:false-negativePMD doesn't flag a problematic piece of codea:false-positivePMD flags a piece of code that is not problematic
Milestone
6.28.0

Description

@jbartolotta-sfdc
jbartolotta-sfdc
opened on Sep 11, 2020
Issue body actions

Affects PMD Version:
6.27.0

Rule:
ApexSharingViolations

Description:
ApexSharingViolations scans inner and outer classes for DML, SOQL, or SOSL. The rule only looks at the outer class for a sharing declaration. As described here the sharing setting applies to the class that performs the data access.

  • Both inner classes and outer classes can be declared as with sharing. The sharing setting applies to all code contained in the class, including initialization code, constructors, and methods.

  • Inner classes do not inherit the sharing setting from their container class.

Code Sample demonstrating the issue:

Example False Positive(Sharing is correctly declared on Inner class)

public class Outer {
   public with sharing class Inner {
      public List<Contact> getAllInnerSoqlSecrets() { return [SELECT Name FROM Contact]; }
   }
}

Example False Negative(Sharing is incorrectly declared on Outer class)

public with sharing class Outer {
   public class Inner {
      public List<Contact> getAllInnerSoqlSecrets() { return [SELECT Name FROM Contact]; }
   }
}

Expected outcome:
The rule is generating both a false-positive and false-negative

Running PMD through: CLI

Activity

  1. jbartolotta-sfdc
    added
    a:bugPMD crashes or fails to analyse a file.
    on Sep 11, 2020
  2. jbartolotta-sfdc commented on Sep 11, 2020

    @jbartolotta-sfdc
    jbartolotta-sfdc
    on Sep 11, 2020
    ContributorAuthor
    More actions

    I have a fix for this. Will submit a PR in the coming days.

    Reacted by Andreas Dangel
  3. adangel
    assigned
    jbartolotta-sfdc
    on Sep 11, 2020
  4. adangel
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    a:false-positivePMD flags a piece of code that is not problematic
    and removed
    a:bugPMD crashes or fails to analyse a file.
    on Sep 11, 2020
  5. jbartolotta-sfdc
    added a commit that references this issue on Sep 17, 2020

    Analyze inner classes for sharing violations

    c6b7a72
  6. adangel
    added
    has:pr
    on Sep 18, 2020
  7. adangel
    added this to the 6.28.0 milestone on Sep 18, 2020
  8. adangel
    closed this as completedin c6b7a72on Sep 24, 2020
  9. adangel
    closed this as completedin #2791on Sep 24, 2020
  10. adangel
    added a commit that references this issue on Sep 24, 2020

    [doc] Update release notes, refs #2791, fixes #2774

    This issue will close once commit eb0f7e4 is merged into the 'main' branch.
    eb0f7e4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @jbartolotta-sfdc
    jbartolotta-sfdc

Labels

a:false-negativePMD doesn't flag a problematic piece of codea:false-positivePMD flags a piece of code that is not problematic

Type

No type

Projects

No projects

    Milestone

    • 6.28.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.