This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch issue/SLING-13330 in repository https://gitbox.apache.org/repos/asf/sling-ide-tooling.git
commit e0d8260eef12e2c07f2fa9422c1f609db61d2937 Author: Robert Munteanu <[email protected]> AuthorDate: Tue Sep 8 17:59:25 2026 +0200 SLING-13330 - FeatureModelContentProvider can throw exceptions if a feature project does not have a feature model path Better handling of null returns from ProjectUtil. --- .../test/impl/FeatureModelContentProviderTest.java | 61 ++++++++++++++++++++++ .../impl/ProvisioningModelContentProviderTest.java | 61 ++++++++++++++++++++++ .../ui/nav/BaseRootFolderContentProvider.java | 3 +- .../ui/nav/FeatureModelContentProvider.java | 3 ++ .../ui/nav/ProvisioningModelContentProvider.java | 3 ++ 5 files changed, 130 insertions(+), 1 deletion(-) diff --git a/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/FeatureModelContentProviderTest.java b/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/FeatureModelContentProviderTest.java new file mode 100644 index 00000000..3013caf9 --- /dev/null +++ b/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/FeatureModelContentProviderTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.ide.test.impl; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertFalse; + +import org.apache.sling.ide.eclipse.ui.nav.FeatureModelContentProvider; +import org.apache.sling.ide.test.impl.helpers.DisableDebugStatusHandlers; +import org.apache.sling.ide.test.impl.helpers.ProjectAdapter; +import org.apache.sling.ide.test.impl.helpers.TemporaryProject; +import org.eclipse.core.resources.IProject; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class FeatureModelContentProviderTest { + + @Rule + public TemporaryProject projectRule = new TemporaryProject(); + + @Rule + public DisableDebugStatusHandlers disableDebugHandlers = new DisableDebugStatusHandlers(); + + private IProject featureProject; + + @Before + public void prepareProject() throws Exception { + + featureProject = projectRule.getProject(); + + ProjectAdapter project = new ProjectAdapter(featureProject); + project.addNatures("org.eclipse.wst.common.project.facet.core.nature"); + + // install feature facet + project.installFacet("sling.feature", "1.0"); + } + + @Test + public void childrenOfProjectWithoutFeatureFolder() { + + FeatureModelContentProvider contentProvider = new FeatureModelContentProvider(); + assertArrayEquals(contentProvider.getChildren(featureProject), new Object[0]); + assertFalse(contentProvider.hasChildren(featureProject)); + } + +} diff --git a/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/ProvisioningModelContentProviderTest.java b/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/ProvisioningModelContentProviderTest.java new file mode 100644 index 00000000..cbcd34ee --- /dev/null +++ b/eclipse/eclipse-test/src/org/apache/sling/ide/test/impl/ProvisioningModelContentProviderTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.ide.test.impl; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertFalse; + +import org.apache.sling.ide.eclipse.ui.nav.ProvisioningModelContentProvider; +import org.apache.sling.ide.test.impl.helpers.DisableDebugStatusHandlers; +import org.apache.sling.ide.test.impl.helpers.ProjectAdapter; +import org.apache.sling.ide.test.impl.helpers.TemporaryProject; +import org.eclipse.core.resources.IProject; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class ProvisioningModelContentProviderTest { + + @Rule + public TemporaryProject projectRule = new TemporaryProject(); + + @Rule + public DisableDebugStatusHandlers disableDebugHandlers = new DisableDebugStatusHandlers(); + + private IProject provisioningProject; + + @Before + public void prepareProject() throws Exception { + + provisioningProject = projectRule.getProject(); + + ProjectAdapter project = new ProjectAdapter(provisioningProject); + project.addNatures("org.eclipse.wst.common.project.facet.core.nature"); + + // install provisioning facet + project.installFacet("sling.launchpad", "1.0"); + } + + @Test + public void childrenOfProjectWithoutFeatureFolder() { + + ProvisioningModelContentProvider contentProvider = new ProvisioningModelContentProvider(); + assertArrayEquals(contentProvider.getChildren(provisioningProject), new Object[0]); + assertFalse(contentProvider.hasChildren(provisioningProject)); + } + +} diff --git a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/BaseRootFolderContentProvider.java b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/BaseRootFolderContentProvider.java index c295e8e2..5ac5b930 100644 --- a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/BaseRootFolderContentProvider.java +++ b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/BaseRootFolderContentProvider.java @@ -36,7 +36,8 @@ public abstract class BaseRootFolderContentProvider<T extends RootFolder> implem @Override public boolean hasChildren(Object parentElement) { // the getChildren is not expensive, therefore we leverage that here - return getChildren(parentElement) != null; + Object[] children = getChildren(parentElement); + return children != null && children.length > 0; } @Override diff --git a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/FeatureModelContentProvider.java b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/FeatureModelContentProvider.java index 27e0487c..e5db5fdd 100644 --- a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/FeatureModelContentProvider.java +++ b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/FeatureModelContentProvider.java @@ -32,6 +32,9 @@ public class FeatureModelContentProvider extends BaseRootFolderContentProvider<F protected FeatureModelRootFolder findRootFolder(IProject project) { IPath modelDirPath = ProjectUtil.getFeatureModelPath(project); + if ( modelDirPath == null ) { + return null; + } IFolder folder = project.getFolder(modelDirPath); if ( !folder.exists() ) { diff --git a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ProvisioningModelContentProvider.java b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ProvisioningModelContentProvider.java index 262a5a3b..3820b1a6 100644 --- a/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ProvisioningModelContentProvider.java +++ b/eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/ProvisioningModelContentProvider.java @@ -32,6 +32,9 @@ public class ProvisioningModelContentProvider extends BaseRootFolderContentProvi protected ProvisioningModelRootFolder findRootFolder(IProject project) { IPath modelDirPath = ProjectUtil.getProvisioningModelPath(project); + if ( modelDirPath == null ) { + return null; + } IFolder folder = project.getFolder(modelDirPath); if ( !folder.exists() ) {
