class Version {

    @VisibleForTesting
    static @Nullable Manifest getManifest(Class<?> clazz) throws IOException {
        URL classURL = clazz.getResource(clazz.getSimpleName() + ".class");
        if (classURL == null) {
            logger.warn("url for class is unexpectedly null: {}", clazz);
            return null;
        }
        String externalForm = classURL.toExternalForm();
        if (!externalForm.startsWith("jar:")) {
            return null;
        }
        URL manifestURL = new URL(externalForm.substring(0, externalForm.lastIndexOf('!'))
                + "!/META-INF/MANIFEST.MF");
        // Closer is used to simulate Java 7 try-with-resources
        Closer closer = Closer.create();
        try {
            InputStream manifestIn = closer.register(manifestURL.openStream());
            return new Manifest(manifestIn);
        } catch (Throwable t) {
            throw closer.rethrow(t);
        } finally {
            closer.close();
        }
    }

    private  Version();

}