This is an automated email from the ASF dual-hosted git repository. davidb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push: new d2f25bf FELIX-6362 Utils ResourceBuilder does not allow java.* imports new cf18cb6 Merge pull request #62 from bosschaert/FELIX-6362 d2f25bf is described below commit d2f25bf4e714d3d16ae41fe70c092c277a1d850e Author: David Bosschaert <dav...@apache.org> AuthorDate: Mon Nov 23 16:56:05 2020 +0000 FELIX-6362 Utils ResourceBuilder does not allow java.* imports --- .../felix/utils/resource/ResourceBuilder.java | 7 ++--- .../felix/utils/resource/ResourceBuilderTest.java | 33 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/utils/src/main/java/org/apache/felix/utils/resource/ResourceBuilder.java b/utils/src/main/java/org/apache/felix/utils/resource/ResourceBuilder.java index a2cec7f..a269300 100644 --- a/utils/src/main/java/org/apache/felix/utils/resource/ResourceBuilder.java +++ b/utils/src/main/java/org/apache/felix/utils/resource/ResourceBuilder.java @@ -309,17 +309,14 @@ public final class ResourceBuilder { clause.attrs.put(Constants.BUNDLE_VERSION_ATTRIBUTE, VersionRange.parseVersionRange(v.toString())); } - // Verify java.* is not imported, nor any duplicate imports. + // Verify no duplicate imports, nor '.' or empty packages. for (String pkgName : clause.paths) { if (!dupeSet.contains(pkgName)) { - // Verify that java.* packages are not imported. - if (pkgName.startsWith("java.")) { - throw new BundleException("Importing java.* packages not allowed: " + pkgName); // The character "." has no meaning in the OSGi spec except // when placed on the bundle class path. Some people, however, // mistakenly think it means the default package when imported // or exported. This is not correct. It is invalid. - } else if (pkgName.equals(".")) { + if (pkgName.equals(".")) { throw new BundleException("Importing '.' is invalid."); // Make sure a package name was specified. } else if (pkgName.length() == 0) { diff --git a/utils/src/test/java/org/apache/felix/utils/resource/ResourceBuilderTest.java b/utils/src/test/java/org/apache/felix/utils/resource/ResourceBuilderTest.java new file mode 100644 index 0000000..eb8bcfe --- /dev/null +++ b/utils/src/test/java/org/apache/felix/utils/resource/ResourceBuilderTest.java @@ -0,0 +1,33 @@ +/* + * 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.felix.utils.resource; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class ResourceBuilderTest { + @Test + public void testImportJavaPackage() throws Exception { + Map<String, String> headers = new HashMap<>(); + headers.put("Bundle-ManifestVersion", "2"); + headers.put("Bundle-SymbolicName", "foo"); + headers.put("Import-Package", "java.util"); + ResourceBuilder.build("http://foo", headers); + } +}