@Test public void testClassWithNoClassFile() throws IOException { assertThat(Version.getManifest(long.class)).isNull(); }
@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 closer = Closer.create(); try { InputStream manifestIn = closer.register(manifestURL.openStream()); return new Manifest(manifestIn); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } }
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 closer = Closer.create(); try { InputStream manifestIn = closer.register(manifestURL.openStream()); return new Manifest(manifestIn); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } } }
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 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(); }
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 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(); static String getVersion(Class<?> baseClass); }
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 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(); static String getVersion(Class<?> baseClass); static final String UNKNOWN_VERSION; }