public static String getPackageName(Class<?> clazz) {
    int lengthDiff = clazz.getName().length() - clazz.getSimpleName().length();
    return lengthDiff == 0 ? clazz.getName() : clazz.getName().substring(0, lengthDiff - 1);
  }
Determines the package name without calling {@code Class.getPackage()}
(which may return null).
spock-core/src/main/java/org/spockframework/util/ReflectionUtil.java