JDK-8200112 : null value when trying to read a manifest file property
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 8u161
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2018-03-21
  • Updated: 2018-04-19
  • Resolved: 2018-04-19
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
various Windows Server versions and various WIndows 7 verions too.

EXTRA RELEVANT SYSTEM CONFIGURATION :
For testing you can use this Manifest file :

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_65-b17 (Oracle Corporation)
Built-By: CLISSON
Built-Date: 2018-03-09 14:36:30
Implementation-Title: Dachser Labelprint Client
Implementation-Vendor: Dachser Intelligent Logistics
Implementation-Version: 2.0.0
Main-Class: com.dachser.labelprint.client.LabelprintApplication
Class-Path: .



A DESCRIPTION OF THE PROBLEM :
Hi,

We provide our customers with an EXE file embedding a BAT and our application JAR file.
When starting the Java application read its META-INF/MANIFEST.MF file to determine the current running version of the product. This information is stored under key "Implementation-Version". But since Java 8 update 161 we retrieve a null (or empty) string ... we use the java.util.jar package to perform the job (see source code for test case).

Greetings.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1 - create a JAR with the provided Manifest file
2 - run the test case

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
we expect to extract a String with value "2.0.0"
ACTUAL -
we retrieve a null value from method Manifest.getMainAttributes().getValue(String)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
no stacktrace.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
String version = null;
// look the local version in the Java JAR Manifest
			InputStream stream = null;
			try {
				stream = VersionService.class.getClassLoader().getResourceAsStream(JarFile.MANIFEST_NAME);
				Manifest manifest = new Manifest(stream);
				version = manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
			} catch (IOException cause) {
				throw new LabelprintException(LabelprintResourceBundle.getInstance().getTranslations().getString("critical.service.version.missing"), cause);
			} finally {
				if (stream != null) {
					try {
						stream.close();
					} catch (IOException e) {
						if (Logger.getRootLogger().isEnabledFor(Level.WARN)) {
							Logger.getRootLogger().warn(String.format("could not close stream of manifest file [%s].", JarFile.MANIFEST_NAME), e);
						}
					}
				}
			}
			// fail if the version number is undetermined
			if (StringUtils.isBlank(version)) {
				throw new RuntimeException("version is missing");
			}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
we asked our customers to go back to previous Java update version (before Java 8 update 161). Some of them accepted. But most of them won't. We think about embedding our own JRE version with our product (it's an EXE file carrying our application JAR).


Comments
Closing as incomplete for now. Will reopen once receive additional details as requested.
03-04-2018

To submitter: I am unable to reproduce the issue. Following is my test case: import java.io.IOException; import java.net.JarURLConnection; import java.net.URL; import java.util.jar.Attributes; import java.util.jar.Manifest; public class JI9053053 { public static void main(String[] args) throws IOException { String version = null; URL jarURL = JI9053053.class.getResource("JI9053053.class"); System.out.println(jarURL); JarURLConnection jurlConn = (JarURLConnection)jarURL.openConnection(); Manifest mf = jurlConn.getManifest(); Attributes attr = mf.getMainAttributes(); version = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION); System.out.println(version); } } Following are the contents of the manifest file: Manifest-Version: 1.0 Ant-Version: Apache Ant 1.9.4 Created-By: 1.8.0_65-b17 (Oracle Corporation) Built-By: CLISSON Built-Date: 2018-03-09 14:36:30 Implementation-Title: Dachser Labelprint Client Implementation-Vendor: Dachser Intelligent Logistics Implementation-Version: 2.0.0 Main-Class: JI9053053 Class-Path: . I used the following to create the jar file and execute it : >>D:\JDK8u161\bin\jar cfm TestLoader.jar D:\ TestCases\mani.txt JI9053053.class >> D:\JDK8u161\bin\java -jar TestLoader.jar jar:file:/D:/TestCases/TestLoader/TestLoader.jar!/JI9053053.class 2.0.0 Can you please provide a complete and verifiable test case to reproduce the issue at our end.
22-03-2018