From 046d98c9d20497d2494876775179bbfcd6955222 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson Date: Wed, 30 Sep 2015 15:11:40 -0500 Subject: [PATCH 1/4] Fix IllegalArgumentException on JDK 1.8.0_60 To determine actual types of parameters for class passed in as lambda to step definition, code uses old Sun ConstantPool to look for dynamic linking data. Previously these values were found at index size()-2; however as of 1.8.0_60 the location appears to have changed to size()-3. Given that the following indexes appear to have empty/invalid values, instead iterate downward from end to find first valid value and use for parameter type determination. --- .../java8/ConstantPoolTypeIntrospector.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java b/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java index fd510914f5..06d76159ec 100644 --- a/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java +++ b/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java @@ -34,8 +34,21 @@ public Type[] getGenericTypes(Class clazz) throws Exception { } private String getTypeString(ConstantPool constantPool) { - String[] memberRef = constantPool.getMemberRefInfoAt(constantPool.getSize() - 2); - return memberRef[2]; + int size = constantPool.getSize(); + String[] memberRef = null; + + // find last element in constantpool with valid memberRef + // - previously always at size-2 index but changed with 1.8.0_60 + for (int i=size-1; i>-1; i--) { + try { + memberRef = constantPool.getMemberRefInfoAt(i); + break; + } catch (IllegalArgumentException e) { + // eat error; null entry at ConstantPool index? + } + } + + return memberRef[2]; } } From dd340923e49f169e1abd3995b29ae1a6dc04d2a6 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson Date: Fri, 2 Oct 2015 09:29:52 -0500 Subject: [PATCH 2/4] #914 Correct with Code Standards Conform to project coding standards regarding tabs, line feeds and encoding. --- .gitattributes | 29 ++++++++++++++++ .../java8/ConstantPoolTypeIntrospector.java | 33 ++++++++++--------- 2 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..656d859056 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,29 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text eol=lf + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +*.java text +*.js text + +# Declare files that will always have CRLF line endings on checkout. +*.sln text eol=crlf + +# Denote all files that are truly binary and should not be modified. +*.png binary +*.jpg binary + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java b/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java index 06d76159ec..c02ce1ffe2 100644 --- a/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java +++ b/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java @@ -25,7 +25,8 @@ public Type[] getGenericTypes(Class clazz) throws Exception { Type[] typeArguments; ConstantPool constantPool = (ConstantPool) Class_getConstantPool.invoke(clazz); String typeString = getTypeString(constantPool); - jdk.internal.org.objectweb.asm.Type[] argumentTypes = jdk.internal.org.objectweb.asm.Type.getArgumentTypes(typeString); + jdk.internal.org.objectweb.asm.Type[] argumentTypes = jdk.internal.org.objectweb.asm.Type + .getArgumentTypes(typeString); typeArguments = new Type[argumentTypes.length]; for (int i = 0; i < argumentTypes.length; i++) { typeArguments[i] = Class.forName(argumentTypes[i].getClassName()); @@ -34,21 +35,21 @@ public Type[] getGenericTypes(Class clazz) throws Exception { } private String getTypeString(ConstantPool constantPool) { - int size = constantPool.getSize(); - String[] memberRef = null; - - // find last element in constantpool with valid memberRef - // - previously always at size-2 index but changed with 1.8.0_60 - for (int i=size-1; i>-1; i--) { - try { - memberRef = constantPool.getMemberRefInfoAt(i); - break; - } catch (IllegalArgumentException e) { - // eat error; null entry at ConstantPool index? - } - } - - return memberRef[2]; + int size = constantPool.getSize(); + String[] memberRef = null; + + // find last element in constantpool with valid memberRef + // - previously always at size-2 index but changed with JDK 1.8.0_60 + for (int i = size - 1; i > -1; i--) { + try { + memberRef = constantPool.getMemberRefInfoAt(i); + break; + } catch (IllegalArgumentException e) { + // eat error; null entry at ConstantPool index? + } + } + + return memberRef[2]; } } From 66a622c58d7e4f920b59425feffa7da875fd199d Mon Sep 17 00:00:00 2001 From: Michael Wilkerson Date: Fri, 2 Oct 2015 09:31:01 -0500 Subject: [PATCH 3/4] Revert "#914 Correct with Code Standards" This reverts commit dd340923e49f169e1abd3995b29ae1a6dc04d2a6. --- .gitattributes | 29 ---------------- .../java8/ConstantPoolTypeIntrospector.java | 33 +++++++++---------- 2 files changed, 16 insertions(+), 46 deletions(-) delete mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 656d859056..0000000000 --- a/.gitattributes +++ /dev/null @@ -1,29 +0,0 @@ -# Set the default behavior, in case people don't have core.autocrlf set. -* text eol=lf - -# Explicitly declare text files you want to always be normalized and converted -# to native line endings on checkout. -*.java text -*.js text - -# Declare files that will always have CRLF line endings on checkout. -*.sln text eol=crlf - -# Denote all files that are truly binary and should not be modified. -*.png binary -*.jpg binary - -# Custom for Visual Studio -*.cs diff=csharp - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java b/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java index c02ce1ffe2..06d76159ec 100644 --- a/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java +++ b/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java @@ -25,8 +25,7 @@ public Type[] getGenericTypes(Class clazz) throws Exception { Type[] typeArguments; ConstantPool constantPool = (ConstantPool) Class_getConstantPool.invoke(clazz); String typeString = getTypeString(constantPool); - jdk.internal.org.objectweb.asm.Type[] argumentTypes = jdk.internal.org.objectweb.asm.Type - .getArgumentTypes(typeString); + jdk.internal.org.objectweb.asm.Type[] argumentTypes = jdk.internal.org.objectweb.asm.Type.getArgumentTypes(typeString); typeArguments = new Type[argumentTypes.length]; for (int i = 0; i < argumentTypes.length; i++) { typeArguments[i] = Class.forName(argumentTypes[i].getClassName()); @@ -35,21 +34,21 @@ public Type[] getGenericTypes(Class clazz) throws Exception { } private String getTypeString(ConstantPool constantPool) { - int size = constantPool.getSize(); - String[] memberRef = null; - - // find last element in constantpool with valid memberRef - // - previously always at size-2 index but changed with JDK 1.8.0_60 - for (int i = size - 1; i > -1; i--) { - try { - memberRef = constantPool.getMemberRefInfoAt(i); - break; - } catch (IllegalArgumentException e) { - // eat error; null entry at ConstantPool index? - } - } - - return memberRef[2]; + int size = constantPool.getSize(); + String[] memberRef = null; + + // find last element in constantpool with valid memberRef + // - previously always at size-2 index but changed with 1.8.0_60 + for (int i=size-1; i>-1; i--) { + try { + memberRef = constantPool.getMemberRefInfoAt(i); + break; + } catch (IllegalArgumentException e) { + // eat error; null entry at ConstantPool index? + } + } + + return memberRef[2]; } } From 16aa3b5f1b1e8d8e322a03c8d508ce074af28776 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson Date: Fri, 2 Oct 2015 20:46:37 -0500 Subject: [PATCH 4/4] #914 Correct with Code Standards Ensure conform to coding standards --- .../java8/ConstantPoolTypeIntrospector.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java b/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java index 06d76159ec..be1f237d30 100644 --- a/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java +++ b/java8/src/main/java/cucumber/runtime/java8/ConstantPoolTypeIntrospector.java @@ -34,21 +34,21 @@ public Type[] getGenericTypes(Class clazz) throws Exception { } private String getTypeString(ConstantPool constantPool) { - int size = constantPool.getSize(); - String[] memberRef = null; - - // find last element in constantpool with valid memberRef - // - previously always at size-2 index but changed with 1.8.0_60 - for (int i=size-1; i>-1; i--) { - try { - memberRef = constantPool.getMemberRefInfoAt(i); - break; - } catch (IllegalArgumentException e) { - // eat error; null entry at ConstantPool index? - } - } - - return memberRef[2]; + int size = constantPool.getSize(); + String[] memberRef = null; + + // find last element in constantPool with valid memberRef + // - previously always at size-2 index but changed with JDK 1.8.0_60 + for (int i = size - 1; i > -1; i--) { + try { + memberRef = constantPool.getMemberRefInfoAt(i); + break; + } catch (IllegalArgumentException e) { + // eat error; null entry at ConstantPool index? + } + } + + return memberRef[2]; } }