File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,17 +12,19 @@ final class _getfield implements OperationInterface
1212 public function execute (): void
1313 {
1414 $ cpInfo = $ this ->getConstantPool ();
15-
1615 $ cp = $ cpInfo [$ this ->readUnsignedShort ()];
16+ $ class = $ cpInfo [$ cp ->getNameAndTypeIndex ()];
1717
18- $ get = $ this ->popFromOperandStack ();
18+ $ name = $ cpInfo [$ class ->getNameIndex ()]->getString ();
19+ $ objectref = $ this ->popFromOperandStack ();
1920
20- $ return = $ get -> getInstance ( $ cpInfo [ $ cpInfo [ $ cp -> getNameAndTypeIndex ()]-> getNameIndex ()]-> getString () );
21+ $ return = $ objectref -> getInvoker ()-> getDynamic ()-> getFields ()-> get ( $ name );
2122
2223 if ($ return !== null ) {
2324 $ this ->pushToOperandStack ($ return );
2425 return ;
2526 }
26- throw new Exception ('Cannot get to undefined Field ' . $ cpInfo [$ cpInfo [$ cp ->getNameAndTypeIndex ()]->getNameIndex ()]->getString () . '' );
27+
28+ throw new Exception ('Cannot get to undefined Field ' . $ name );
2729 }
2830}
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace PHPJava \Tests ;
3+
4+ use PHPUnit \Framework \TestCase ;
5+
6+ class GetFieldTest extends Base
7+ {
8+ protected $ fixtures = [
9+ 'GetFieldTest ' ,
10+ ];
11+
12+ public function testGetField ()
13+ {
14+ $ actual = $ this ->initiatedJavaClasses ['GetFieldTest ' ]
15+ ->getInvoker ()
16+ ->getStatic ()
17+ ->getMethods ()
18+ ->call ('getField ' )
19+ ->getValue ();
20+
21+ $ this ->assertEquals (1 , $ actual );
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ class GetFieldTest
2+ {
3+ public int value = 1 ;
4+
5+ public static int getField () {
6+ GetFieldTest instance = new GetFieldTest ();
7+ return instance .value ;
8+ }
9+ }
You can’t perform that action at this time.
0 commit comments