-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix package name comparison on Java 8 (#4077)
`Class.getPackage()` returns `null` for the default package on Java 8. This is now handled by inspecting the fully qualified class name rather than throwing a `NullPointerException`. Fixes #4076.
- Loading branch information
1 parent
061fb41
commit 35d3dd7
Showing
7 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
junit-platform-commons/src/main/java/org/junit/platform/commons/util/PackageNameUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.util; | ||
|
||
import static org.junit.platform.commons.util.PackageUtils.DEFAULT_PACKAGE_NAME; | ||
|
||
/** | ||
* Collection of utilities for working with package names. | ||
* | ||
* <h2>DISCLAIMER</h2> | ||
* | ||
* <p>These utilities are intended solely for usage within the JUnit framework | ||
* itself. <strong>Any usage by external parties is not supported.</strong> | ||
* Use at your own risk! | ||
* | ||
* @since 1.11.3 | ||
*/ | ||
class PackageNameUtils { | ||
|
||
static String getPackageName(Class<?> clazz) { | ||
Package p = clazz.getPackage(); | ||
if (p != null) { | ||
return p.getName(); | ||
} | ||
String className = clazz.getName(); | ||
int index = className.lastIndexOf('.'); | ||
return index == -1 ? DEFAULT_PACKAGE_NAME : className.substring(0, index); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
junit-platform-commons/src/main/java9/org/junit/platform/commons/util/PackageNameUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.platform.commons.util; | ||
|
||
/** | ||
* Collection of utilities for working with package names. | ||
* | ||
* <h2>DISCLAIMER</h2> | ||
* | ||
* <p>These utilities are intended solely for usage within the JUnit framework | ||
* itself. <strong>Any usage by external parties is not supported.</strong> | ||
* Use at your own risk! | ||
* | ||
* @since 1.11.3 | ||
*/ | ||
class PackageNameUtils { | ||
|
||
static String getPackageName(Class<?> clazz) { | ||
return clazz.getPackageName(); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
platform-tooling-support-tests/projects/vintage/src/test/java/DefaultPackageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
/* | ||
* Copyright 2015-2024 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
import com.example.vintage.VintageTest; | ||
|
||
import org.junit.Ignore; | ||
|
||
/** | ||
* Reproducer for https://github.com/junit-team/junit5/issues/4076 | ||
*/ | ||
@Ignore | ||
public class DefaultPackageTest extends VintageTest { | ||
void packagePrivateMethod() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters