Bug 550480 - ClassFile.addFieldInfos throws
ArrayIndexOutOfBoundsException - part 2

Change-Id: I2aedda2b757e060fef815127158171efde362847
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest2.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest2.java
index 53c49bf..49a9c05 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest2.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest2.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2018 Andrey Loskutov and others.
+ * Copyright (c) 2018, 2020 Andrey Loskutov and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -404,4 +404,22 @@
 				"interface gwz {}\n" +
 				"interface gxc {}\n";
 	}
+	public void testBug550480() {
+		StringBuilder source = new StringBuilder();
+		source.append("package p;\n");
+		String[] names = new String[571];
+		for (int i = 0; i < 571; i++) {
+			names[i] = "I"+i;
+			source.append("interface ").append(names[i]).append(" {}\n");
+		}
+		source.append("public abstract class hft implements ");
+		source.append(String.join(", ", names));
+		source.append("\n{\n}\n");
+		runConformTest(
+			new String[] {
+				"p/hft.java",
+				source.toString()
+			});
+	}
+
 }
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
index 4f62474..974f012 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
@@ -5778,6 +5778,9 @@
 			if ((binding.tagBits & TagBits.HasMissingType) != 0) {
 				continue;
 			}
+			if (this.contentsOffset + 4 >= this.contents.length) {
+				resizeContents(4); // 2 bytes this iteration plus 2 bytes after the loop
+			}
 			interfaceCounter++;
 			int interfaceIndex = this.constantPool.literalIndexForType(binding);
 			this.contents[this.contentsOffset++] = (byte) (interfaceIndex >> 8);