Fixed Bug 518490: [9] Export as Jar fails when a module info is present
in the project

Change-Id: Ic2956dd4805b3263513d5d51f2533a7189f71747
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index 1fa23f1..4db01e8 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -759,6 +759,7 @@
 	public static final String LIB_DIR = Util.getOutputDirectory() + File.separator + "lib";
 
 	public final static String PACKAGE_INFO_NAME = new String(TypeConstants.PACKAGE_INFO_NAME);
+	public final static String MODULE_INFO_NAME = new String(TypeConstants.MODULE_INFO_NAME);
 
 	public static boolean SHIFT = false;
 
@@ -2716,6 +2717,7 @@
 			// Compute class name by removing ".java" and replacing slashes with dots
 			String className = sourceFile.substring(0, sourceFile.length() - 5).replace('/', '.').replace('\\', '.');
 			if (className.endsWith(PACKAGE_INFO_NAME)) return;
+			if (className.endsWith(MODULE_INFO_NAME)) return;
 
 			if (vmArguments != null) {
 				if (this.verifier != null) {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleAttributeTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleAttributeTests.java
new file mode 100644
index 0000000..86722c6
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleAttributeTests.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2017 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import java.io.File;
+
+import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.util.IClassFileAttribute;
+import org.eclipse.jdt.core.util.IClassFileReader;
+
+import junit.framework.Test;
+
+public class ModuleAttributeTests extends AbstractRegressionTest {
+
+	public ModuleAttributeTests(String name) {
+		super(name);
+	}
+
+	public static Class<?> testClass() {
+		return ModuleAttributeTests.class;
+	}
+
+	// Use this static initializer to specify subset for tests
+	// All specified tests which does not belong to the class are skipped...
+	static {
+//		TESTS_PREFIX = "testBug95521";
+//		TESTS_NAMES = new String[] { "testBug359495" };
+//		TESTS_NUMBERS = new int[] { 53 };
+//		TESTS_RANGE = new int[] { 23 -1,};
+	}
+	public static Test suite() {
+		return buildMinimalComplianceTestSuite(testClass(), F_9);
+	}
+
+	// basic test to check for presence of module attribute in module-info.class
+	public void test001() throws Exception {
+		this.runConformTest(
+			new String[] {
+				"module-info.java",
+				"module test {\n" +
+				"}\n",
+				});
+		IClassFileReader cfr = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "module-info.class", IClassFileReader.CLASSFILE_ATTRIBUTES);
+		assertNotNull("Error reading module-info.class", cfr);
+		IClassFileAttribute moduleAttribute = null;
+		IClassFileAttribute[] attrs = cfr.getAttributes();
+		for (int i=0,max=attrs.length;i<max;i++) {
+			if (new String(attrs[i].getAttributeName()).equals("Module")) {
+				moduleAttribute = attrs[i];
+			}
+		}
+		assertNotNull("Module attribute not found", moduleAttribute);
+	}
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
index 38f16b3..246467b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -163,7 +163,7 @@
 	since_9.add(GenericsRegressionTest_9.class);
 	since_9.add(InterfaceMethodsTest_9.class);
 	since_9.add(Deprecated9Test.class);
-
+	since_9.add(ModuleAttributeTests.class);
 	
 	// Build final test suite
 	TestSuite all = new TestSuite(TestAll.class.getName());
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/IConstantPoolConstant.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/IConstantPoolConstant.java
index ff6ed22..abe8f8b 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/IConstantPoolConstant.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/util/IConstantPoolConstant.java
@@ -1,10 +1,14 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
  *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ * 
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
@@ -42,6 +46,15 @@
 	 */
 	int CONSTANT_InvokeDynamic = 18;
 
+	/**
+	 * @since 3.13
+	 */
+	int CONSTANT_Module = 19;
+	/**
+	 * @since 3.13
+	 */
+	int CONSTANT_Package = 20;
+
 	int CONSTANT_Methodref_SIZE = 5;
 	int CONSTANT_Class_SIZE = 3;
 	int CONSTANT_Double_SIZE = 9;
@@ -67,6 +80,15 @@
 	int CONSTANT_InvokeDynamic_SIZE = 5;
 
 	/**
+	 * @since 3.13
+	 */
+	int CONSTANT_Module_SIZE = 3;
+	
+	/**
+	 * @since 3.13
+	 */
+	int CONSTANT_Package_SIZE = 3;
+	/**
 	 * The constant is described at 5.4.3.5 in the Java 7 VM specification (part 3).
 	 * @since 3.8
 	 */
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ClassFileReader.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ClassFileReader.java
index b5cc144..81b196a 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ClassFileReader.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ClassFileReader.java
@@ -1,10 +1,14 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2011, 2017 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
  *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ * 
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *        Andy Clement - Contributions for
@@ -154,6 +158,14 @@
 						constantPoolOffsets[i] = readOffset;
 						readOffset += IConstantPoolConstant.CONSTANT_InvokeDynamic_SIZE;
 						break;
+					case IConstantPoolConstant.CONSTANT_Module:
+						constantPoolOffsets[i] = readOffset;
+						readOffset += IConstantPoolConstant.CONSTANT_Module_SIZE;
+						break;
+					case IConstantPoolConstant.CONSTANT_Package:
+						constantPoolOffsets[i] = readOffset;
+						readOffset += IConstantPoolConstant.CONSTANT_Package_SIZE;
+						break;
 					default:
 						throw new ClassFormatException(ClassFormatException.INVALID_TAG_CONSTANT);
 				}