diff options
author | Manoj Palat | 2020-01-02 05:52:14 +0000 |
---|---|---|
committer | Manoj Palat | 2020-01-02 05:52:14 +0000 |
commit | f765c2d47f596d33a94f2cf95d52b12bfd8fb1ca (patch) | |
tree | fbe535f578a380dc89deb798d1b5e382ebc7ce67 | |
parent | efc21fe356ef830324cf0619abec4d9439239152 (diff) | |
download | eclipse.jdt.core-f765c2d47f596d33a94f2cf95d52b12bfd8fb1ca.tar.gz eclipse.jdt.core-f765c2d47f596d33a94f2cf95d52b12bfd8fb1ca.tar.xz eclipse.jdt.core-f765c2d47f596d33a94f2cf95d52b12bfd8fb1ca.zip |
decode bug fix
Change-Id: Icff7d674cbf6d1a6819c2bcd0d39594ae4fa9d5c
3 files changed, 29 insertions, 6 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java index b040dda7d2..19fc97cf22 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java @@ -33,7 +33,7 @@ public class RecordsRestrictedClassTest extends AbstractRegressionTest { static { // TESTS_NUMBERS = new int [] { 40 }; // TESTS_RANGE = new int[] { 1, -1 }; -// TESTS_NAMES = new String[] { "testBug553152_018" }; +// TESTS_NAMES = new String[] { "testBug558494" }; } public static Class<?> testClass() { @@ -1637,6 +1637,29 @@ public void testBug558494_003() throws Exception { "Components:\n" + " \n"; RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Forts.class", ClassFileBytesDisassembler.SYSTEM); - +} +public void testBug558494_004() throws Exception { + runConformTest( + new String[] { + "X.java", + "record Forts(String[] wonders, int x){\n"+ + "}\n"+ + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " Forts p = new Forts(new String[] {\"Amber\", \"Nahargarh\", \"Jaigarh\"}, 3);\n"+ + " System.out.println(p.toString());\n"+ + " }\n"+ + "}\n" + }, + "Forts@28108256"); + String expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 [Ljava/lang/String;\n" + + "java.lang.String[] wonders;\n" + + "// Component descriptor #8 I\n" + + "int x;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Forts.class", ClassFileBytesDisassembler.SYSTEM); } }
\ No newline at end of file diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java index ea62941e83..ca1dd0e46b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java @@ -494,9 +494,9 @@ private void decodeRecords(int readOffset, char[] attributeName) { offset += 2; this.recordComponents = new ComponentInfo[this.recordComponentsCount]; for (int j = 0; j < this.recordComponentsCount; j++) { - ComponentInfo component = ComponentInfo.createComponent(this.reference, this.constantPoolOffsets, readOffset, this.version); + ComponentInfo component = ComponentInfo.createComponent(this.reference, this.constantPoolOffsets, offset, this.version); this.recordComponents[j] = component; - readOffset += component.sizeInBytes(); + offset += component.sizeInBytes(); } } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfo.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfo.java index 56438f6341..8b4e08e598 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfo.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ComponentInfo.java @@ -192,7 +192,7 @@ public char[] getGenericSignature() { public char[] getName() { if (this.name == null) { // read the name - int utf8Offset = this.constantPoolOffsets[u2At(2)] - this.structOffset; + int utf8Offset = this.constantPoolOffsets[u2At(0)] - this.structOffset; this.name = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); } return this.name; @@ -216,7 +216,7 @@ public long getTagBits() { public char[] getTypeName() { if (this.descriptor == null) { // read the signature - int utf8Offset = this.constantPoolOffsets[u2At(4)] - this.structOffset; + int utf8Offset = this.constantPoolOffsets[u2At(2)] - this.structOffset; this.descriptor = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); } return this.descriptor; |