wttech / AEM-Rules-for-SonarQube

SonarQube plugin with set of rules detecting possible bugs and bad smells specific for AEM development.
Apache License 2.0
116 stars 50 forks source link

UnableToSupportSlingSchedulerCheck NPE #217

Closed esodot closed 2 years ago

esodot commented 2 years ago

Hello, we are running the Sonar check on Adobe Experience Manager Custom Application and getting a Sonar NPE


com.adobe.platform.experience.selfservice.cqrules.checks.java.UnableToSupportSlingSchedulerCheck - AMSCORE-554 on file /build_root/build/aem/core/src/main/java/aem/zeppelin/commons/model/FilterUsedMachineHomepageModel.java, To help improve SonarJava, please report this problem to SonarSource : see https://www.sonarqube.org/community/
java.lang.NullPointerException: null
    at com.adobe.platform.experience.selfservice.cqrules.checks.java.UnableToSupportSlingSchedulerCheck.getClassFullyQualifierName(UnableToSupportSlingSchedulerCheck.java:82)
    at com.adobe.platform.experience.selfservice.cqrules.checks.java.UnableToSupportSlingSchedulerCheck.visitNode(UnableToSupportSlingSchedulerCheck.java:67)
    at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:95)
    at org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:120)
    at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:97)
    at org.sonar.java.ast.visitors.SubscriptionVisitor.scanTree(SubscriptionVisitor.java:78)
    at org.sonar.java.ast.visitors.SubscriptionVisitor.scanFile(SubscriptionVisitor.java:64)
    at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:135)
    at org.sonar.java.model.VisitorsBridge.lambda$visitFile$0(VisitorsBridge.java:127)
    at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:407)
    at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:127)
    at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:96)
    at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:68)
    at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:116)
    at org.sonar.java.JavaSquid.scan(JavaSquid.java:110)
    at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:93)
    at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:45)
    at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:88)
    at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:62)
    at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:74)
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:164)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:319)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:314)
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:312)
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:288)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
    at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:82)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
    at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:131)
    at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at com.sun.proxy.$Proxy27.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
    at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:63)
    at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:108)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
esodot commented 2 years ago

Our class which seems to case the error looks like this:

package aem.zeppelin.commons.model;

import aem.zeppelin.commons.config.AppConstants;
import aem.zeppelin.commons.handler.link.LinkHandler;
import aem.zeppelin.commons.utils.PageUtils;
import aem.zeppelin.filters.pojo.ZBMFilter;
import com.day.cq.wcm.api.Page;
import com.day.text.Text;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.apache.sling.models.annotations.injectorspecific.Self;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * Sling Model for the Used Machine Filter component
 */
@Slf4j
@Model(adaptables = { SlingHttpServletRequest.class })
public class FilterUsedMachineHomepageModel {
    @ScriptVariable
    private Page currentPage;
    @Self
    private LinkHandler linkHandler;

    @Getter
    private List<Category> categories = new ArrayList<>();
    @Getter
    private Category defaultCategory;

    @PostConstruct
    protected void activate() {
        List<Page> categoryPages = getCategoryPages();
        for (Page categoryPage : categoryPages) {
            Category category = new Category(getUrlFromPath(categoryPage), categoryPage.getTitle());
            if (PageUtils.isAllCategoryPage(categoryPage)) {
                this.defaultCategory = category;
            } else {
                categories.add(category);
            }
        }
    }

    private List<Page> getCategoryPages() {
        String sgePath = Text.getAbsoluteParent(currentPage.getPath(), AppConstants.SGE_LEVEL);
        String categoriesRoot = sgePath + "/gebrauchtmaschinen";
        Page categoriesRootPage = currentPage.getPageManager().getPage(categoriesRoot);
        return Lists.newArrayList(categoriesRootPage.listChildren());
    }

    public String getManufacturerFilterId() {
        return ZBMFilter.MANUFACTURER.id;
    }

    public String getLocationFilterId() {
        return ZBMFilter.LOCATION.id;
    }

    private String getUrlFromPath(Page categoryPage) {
        return linkHandler.build(categoryPage).getUrl();
    }

    @Getter
    @AllArgsConstructor
    public static class Category {
        private String url;
        private String label;
    }
}
toniedzwiedz commented 2 years ago

Hi, sorry I missed this. The stack trace mentions a null pointer exception in a class from the com.adobe.platform.experience.selfservice.cqrules.checks.java package, which isn't part of this plugin.

I know Adobe themselves have been developing custom rules to integrate into the Cloud Manager pipeline. This may be related but I'm not sure. I don't think that code has been open-sourced.

Please contact Adobe if this is still an issue.