2015-09-22 16 views
9

के साथ "निरंतर पूल इंडेक्स पर गलत प्रकार" अपवाद प्राप्त करना मैं ककड़ी की जावा 8 बोली के लिए एक उदाहरण प्रोजेक्ट सेट अप करने का प्रयास कर रहा हूं। मेरी समस्या यह है कि मुझे यह नहीं चल रहा है। मुझे हमेशा अपवादों का निम्नलिखित पदानुक्रम मिलता है:हमेशा ककड़ी-जावा 8

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.068 sec <<< FAILURE! - in soy.wimmer.CucumberIT 
Feature: Cucumber with Java8 Time elapsed: 0.051 sec <<< ERROR! 
cucumber.runtime.CucumberException: Failed to instantiate class soy.wimmer.CucumberStepdefs 
[…] 
Caused by: java.lang.reflect.InvocationTargetException: null 
[…] 
Caused by: cucumber.runtime.CucumberException: java.lang.IllegalArgumentException: Wrong type at constant pool index 
[…] 
Caused by: java.lang.IllegalArgumentException: Wrong type at constant pool index 
    at sun.reflect.ConstantPool.getMemberRefInfoAt0(Native Method) 
    at sun.reflect.ConstantPool.getMemberRefInfoAt(ConstantPool.java:47) 
    at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getTypeString(ConstantPoolTypeIntrospector.java:37) 
    at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getGenericTypes(ConstantPoolTypeIntrospector.java:27) 
    at cucumber.runtime.java.Java8StepDefinition.<init>(Java8StepDefinition.java:45) 
    at cucumber.runtime.java.JavaBackend.addStepDefinition(JavaBackend.java:162) 
    at cucumber.api.java8.En.Given(En.java:190) 
    at soy.wimmer.CucumberStepdefs.<init>(CucumberStepdefs.java:8) 
[…] 

Results : 

Tests in error: 
    Failed to instantiate class soy.wimmer.CucumberStepdefs 

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0 

मुझे कोई संकेत नहीं है कि मुझे यह त्रुटि क्यों मिलती है और न ही इसे कैसे ठीक किया जाए।

मैंने मैवेन प्रोजेक्ट में सबकुछ पैक किया है। लेआउट कि तरह है:

./src/test/java/soy/wimmer/CucumberIT.java 
./src/test/java/soy/wimmer/CucumberStepdefs.java 
./src/test/resources/cucumber/cucumber-java8.feature 
./pom.xml 

निर्भरता मैं pom.xml में शामिल हैं:

<dependencies>                
    <dependency>                
     <groupId>info.cukes</groupId>           
     <artifactId>cucumber-java8</artifactId>        
     <version>1.2.3</version>            
     <scope>test</scope>             
    </dependency>                

    <dependency>                
     <groupId>info.cukes</groupId>           
     <artifactId>cucumber-junit</artifactId>        
     <version>1.2.3</version>            
     <scope>test</scope>             
    </dependency>                

    <dependency>                
     <groupId>junit</groupId>            
     <artifactId>junit</artifactId>          
     <version>4.12</version>            
     <scope>test</scope>             
    </dependency>                
</dependencies> 

इसके अतिरिक्त pom.xml केवल संकलक और फेल सेफ प्लगइन लोड करता है।

CucumberIT.java की मेरी परिभाषा:

package soy.wimmer;                

import cucumber.api.CucumberOptions;            
import cucumber.api.junit.Cucumber;            
import org.junit.runner.RunWith;             

@RunWith(Cucumber.class)               
@CucumberOptions(features = "classpath:cucumber")         
public class CucumberIT {               
}   

मेरे सुविधा परिभाषा:

Feature: Cucumber with Java8              
     As a developer               
     I want to use Cucumber-java8            
     So that I have nicer step definitions          

     Scenario: Let's try it             
       Given I have some dummy code          
       When I try to test it            
       Then it should work with cucumber-java8 

और ये मेरे कदम परिभाषाएं दी गई हैं:

package soy.wimmer;                

import cucumber.api.PendingException;            
import cucumber.api.java8.En;              

public class CucumberStepdefs implements En {          
    public CucumberStepdefs() {             
     Given("^I have some dummy code$",() -> {         
      // Write code here that turns the phrase above into concrete actions 
      throw new PendingException();           
     });                  

     When("^I try to test it$",() -> {          
      // Write code here that turns the phrase above into concrete actions 
      throw new PendingException();           
     });                  

     Then("^it should work with cucumber-java(\\d+)$", (Integer arg1) -> {  
      // Write code here that turns the phrase above into concrete actions 
      throw new PendingException();           
     });                  
    }                    
} 

किसी भी विचार है कि मैं क्या कर रहा हूँ यहाँ गलत है?

+0

ठीक है, अपवाद संदेश में वास्तविक प्रकार की कमी है, लेकिन मुझे लगता है कि यह '18' टाइप है और [यह उत्तर] (http://stackoverflow.com/a/23625762/2711488) लागू होता है। संक्षेप में, ऐसा लगता है कि ककड़ी जावा 8 के लिए उपयुक्त नहीं है, वास्तव में, यह 100% जावा 7 संगत भी नहीं है ... – Holger

+0

यह एक Invokedynamic हो सकता है क्योंकि कक्षा के निर्माता में लैम्ब्डा अभिव्यक्तियां हैं। लेकिन मैंने pom.xml में स्रोत और लक्ष्य संस्करण 1.8 के लिए कंपाइलर को कॉन्फ़िगर किया है और यह चरण परिभाषाएं है और इसलिए स्थानीय स्तर पर संकलित एक वर्ग है, नहीं? –

+0

जैसा कि लिंक किए गए उत्तर में कहा गया है, मुद्दा * कंपाइलर नहीं है।समस्या यह है कि एक * रनटाइम * उपकरण है जो संकलित कक्षा फ़ाइल, उर्फ ​​बाइटकोड को संसाधित करने का प्रयास करता है। 'IllegalArgumentException' को फेंकने वाली विधि को देखें। – Holger

उत्तर

10

समस्या इसलिए होती है क्योंकि ककड़ी की जावा 8 बोली ओरेकल के जेडीके 8 के कार्यान्वयन विवरण का उपयोग करती है।

मैं ओपनजेडीके 8 का उपयोग डेबियन द्वारा पैक किया गया था जो निरंतर पूल के एक अलग संगठन का कारण बनता है। जब मैं ओरेकल के जेडीके 8 के साथ ऐसा करने की कोशिश करता हूं तो सब कुछ अपेक्षित काम करता है।

आप इसे खुद की कोशिश करना चाहते हैं, तो मैं प्रकाशित GitHub पर पूर्ण उदाहरण परियोजना: https://github.com/cucumber/cucumber-jvm/issues/912

आप जाँच कर सकते हैं: https://github.com/mawis/cucumber-java8-test

मैं भी ककड़ी-JVM के मुद्दे पर नजर यहां पर एक बग रिपोर्ट यह देखने के लिए कि क्या समस्या भविष्य में तय की गई है, ट्रैकर जारी करें।

अब यदि आप ककड़ी-जावा 8 का उपयोग करना चाहते हैं तो ऐसा लगता है कि आपको जेडीके के ओरेकल के कार्यान्वयन का उपयोग करना होगा।

(इस समस्या को हल करने के लिए प्रसिद्धि सवाल का अपनी टिप्पणी के साथ होल्गर के अंतर्गत आता है। मैं सिर्फ एक सारांश के रूप में इस सवाल का जवाब लिखना चाहते थे।)

+1

तो अगर मैं इसे सही तरीके से पढ़ रहा हूं, तो मुझे यह तब तक देखना चाहिए जब तक मैं ओरेकल के जेडीके का उपयोग कर रहा हूं। हालांकि, मुझे मूल पोस्टर के समान सटीक त्रुटि मिलती है। मैं जावा संस्करण 1.8.0_60 का उपयोग कर रहा हूं, जिसे ओरेकल जेडीके के हिस्से के रूप में डाउनलोड किया गया है। –

+5

ऐसा लगता है कि आप जिस जेडीके का उपयोग कर रहे हैं उसके संस्करण पर भी निर्भर करता है। ओरेकल के हालिया जेडीके भी काम नहीं कर रहे हैं। –

7

बस 1.2.5 संस्करण है जो हाल ही मेंकिया गया है जारी किया गया का उपयोग करें। इसने स्वीकृत उत्तर द्वारा संदर्भित बग को हल किया।

संबंधित मुद्दे