java - Bad type on the operand stack in arraylength -
i trying test method using powermock. haven't written test cases yet. trying set class mocking. here have far:
@runwith(powermockrunner.class) @preparefortest({ readrubric.class }) public class readrubrictest { @before public void setup() throws exception { powermockito.mock(readrubric.class); } @after public void teardown() throws exception { } @test public void invalidfile() throws exception { } } when try run test following error.
java.lang.verifyerror: bad type on operand stack in arraylength exception details: location: com/cerner/devcenter/wag/processor/readrubric.readrubric()ljava/util/list; @809: arraylength reason: invalid type: 'java/lang/object' (current frame, stack[0]) current frame: bci: @809 flags: { } locals: { 'java/util/arraylist', 'au/com/bytecode/opencsv/csvreader', top, top, '[ljava/lang/string;', 'com/cerner/devcenter/wag/processor/rule', 'java/lang/object', 'java/lang/object', top, top, top, top, top, top, top, 'java/lang/object' } stack: { 'java/lang/object' } java -version on cmd gives me 1.7.0_65
java_home set c:\program files\java\jdk1.7.0_65
on eclipse using jre 7 , compiler level 1.7
in maven, have added following dependency allow switch cases accept strings instead of chars:
<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.0</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> can me in solving issue?
here method testing:
public static list<rule> readrubric() throws wagexception, ioexception { list<rule> rulelist = new arraylist<rule>(); csvreader rubricreader = null; file file = new file(rubric_file_name); filereader filereader = new filereader(file); rubricreader = new csvreader(filereader); string[] rulerecord = null; //rubricreader.readnext(); while ((rulerecord = rubricreader.readnext()) != null) { rule rule = new rule(); rule.setrulename(rulerecord[0].trim()); string parameters[] = rulerecord[1].split(","); rule.addparameter(arrays.aslist(parameters)); rule.setpoints(integer.parseint(rulerecord[2].trim())); rule.setruleengine(rulerecord[3].trim()); rule.setcomment(rulerecord[4].trim()); rulelist.add(rule); } rubricreader.close(); return rulelist; } i found solution online: says need add -xx:-usesplitverifier vm arguments when run test. test runs when this. need run maven, solution says need add following plugin maven:
<plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-surefire-plugin</artifactid> <version>2.14.1</version> <configuration> <argline>-xx:-usesplitverifier</argline> </configuration> </plugin> </plugins> but after adding pom, particulair test fails. link solution
so after working on hours, found root cause of problem. in java 7u65, made byte code verifier more strict result, byte code verifier reading powermock byte code , throwing verifyerror. ,basically, powermock's byte code not passing byte code verifier. way around add -xx:-usesplitverifier vm arguments or switch java 6.
in case, when remove rulerecord[1].split(",") , when implement own split functionality, tests work fine. guess powermock messes bytecode when use,for e.g, methods whennew(). hope helps.
Comments
Post a Comment