Skip to content

Commit

Permalink
new files for fix to BYTEMAN-219
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed Nov 26, 2012
1 parent 19c2683 commit 29c9870
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 41 deletions.
30 changes: 30 additions & 0 deletions agent/pom.xml
Expand Up @@ -779,6 +779,21 @@
<argLine>-javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestAfterCallAssign.btm</argLine> <argLine>-javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestAfterCallAssign.btm</argLine>
</configuration> </configuration>
</execution> </execution>
<execution>
<id>bugfixes.TestAbstractInterfaceCall</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<forkMode>once</forkMode>
<includes>
<include>org/jboss/byteman/tests/bugfixes/TestAbstractInterfaceCall.class</include>
</includes>
<argLine>-javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestAbstractInterfaceCall.btm</argLine>
</configuration>
</execution>
<!-- dynamic rule submission <!-- dynamic rule submission
n.b. submit test does not use a script on the command line n.b. submit test does not use a script on the command line
instead it sets listener true and uplaods the rules from the test program instead it sets listener true and uplaods the rules from the test program
Expand Down Expand Up @@ -1464,6 +1479,21 @@
<argLine>-Dorg.jboss.byteman.compile.to.bytecode -javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestAfterCallAssign.btm</argLine> <argLine>-Dorg.jboss.byteman.compile.to.bytecode -javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestAfterCallAssign.btm</argLine>
</configuration> </configuration>
</execution> </execution>
<execution>
<id>bugfixes.TestAbstractInterfaceCall.compiled</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<forkMode>once</forkMode>
<includes>
<include>org/jboss/byteman/tests/bugfixes/TestAbstractInterfaceCall.class</include>
</includes>
<argLine>-Dorg.jboss.byteman.compile.to.bytecode -javaagent:${project.build.directory}/byteman-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestAbstractInterfaceCall.btm</argLine>
</configuration>
</execution>
<!-- dynamic rule submission compiled <!-- dynamic rule submission compiled
submit test does not use a script on the command line submit test does not use a script on the command line
instead it sets listener true and uplaods the rules from the test program instead it sets listener true and uplaods the rules from the test program
Expand Down
Expand Up @@ -413,7 +413,7 @@ public void compile(MethodVisitor mv, CompileContext compileContext) throws Comp


if (recipient == null) { if (recipient == null) {
mv.visitMethodInsn(Opcodes.INVOKESTATIC, ownerName, method.getName(), getDescriptor()); mv.visitMethodInsn(Opcodes.INVOKESTATIC, ownerName, method.getName(), getDescriptor());
} else if (recipient.getClass().isInterface()) { } else if (method.getDeclaringClass().isInterface()) {
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ownerName, method.getName(), getDescriptor()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ownerName, method.getName(), getDescriptor());
} else { } else {
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ownerName, method.getName(), getDescriptor()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ownerName, method.getName(), getDescriptor());
Expand Down
41 changes: 35 additions & 6 deletions agent/src/test/java/org/jboss/byteman/tests/auxiliary/C3.java
@@ -1,11 +1,40 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
* @authors Andrew Dinn
*/

package org.jboss.byteman.tests.auxiliary; package org.jboss.byteman.tests.auxiliary;


import org.jboss.byteman.tests.Test;

/** /**
* Created by IntelliJ IDEA. * test class for fix to BYTEMAN-219
* User: adinn
* Date: 26/11/12
* Time: 12:31
* To change this template use File | Settings | File Templates.
*/ */
public class C3 { public abstract class C3 implements I5
{
// n.b. this class does not implement interfaceMethod() inherited from I5
// but it's instantiable subclasses always will!
public void testMethod(Test test)
{
test.log("inside C3.testMethod");
}
} }
40 changes: 34 additions & 6 deletions agent/src/test/java/org/jboss/byteman/tests/auxiliary/C4.java
@@ -1,11 +1,39 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
* @authors Andrew Dinn
*/

package org.jboss.byteman.tests.auxiliary; package org.jboss.byteman.tests.auxiliary;


import org.jboss.byteman.tests.Test;

/** /**
* Created by IntelliJ IDEA. * test class for fix to BYTEMAN-219
* User: adinn
* Date: 26/11/12
* Time: 12:33
* To change this template use File | Settings | File Templates.
*/ */
public class C4 { public class C4 extends C3
{
// this non-abstract class has to implement interfaceMethod() inherited from I5 via C3
public void interfaceMethod(Test test)
{
test.log("inside C4.interfaceMethod");
}
} }
36 changes: 30 additions & 6 deletions agent/src/test/java/org/jboss/byteman/tests/auxiliary/I5.java
@@ -1,11 +1,35 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
* @authors Andrew Dinn
*/

package org.jboss.byteman.tests.auxiliary; package org.jboss.byteman.tests.auxiliary;


import org.jboss.byteman.tests.Test;

/** /**
* Created by IntelliJ IDEA. * test class for fix to BYTEMAN-219
* User: adinn
* Date: 26/11/12
* Time: 12:30
* To change this template use File | Settings | File Templates.
*/ */
public class I5 { public interface I5
{
public void interfaceMethod(Test test);
} }
@@ -1,11 +1,67 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
* @authors Andrew Dinn
*/
package org.jboss.byteman.tests.bugfixes; package org.jboss.byteman.tests.bugfixes;


import org.jboss.byteman.tests.Test;
import org.jboss.byteman.tests.auxiliary.C3;
import org.jboss.byteman.tests.auxiliary.C4;
import org.jboss.byteman.tests.auxiliary.I5;


/** /**
* Created by IntelliJ IDEA. * Test for BYTEMAN-219 where a call to an interface method of an abstract class failed to typecheck
* User: adinn * because there was no implementation on the abstract class.
* Date: 26/11/12
* Time: 12:26
* To change this template use File | Settings | File Templates.
*/ */
public class TestAbstractInterfaceCall { public class TestAbstractInterfaceCall extends Test
} {
private int run;

public TestAbstractInterfaceCall()
{
super(TestAbstractInterfaceCall.class.getCanonicalName());
}

public void test()
{
C4 c4 = new C4();
try {
log("calling C4.testMethod");
c4.testMethod(this);
log("called C4.testMethod");
} catch (Exception e) {
log(e);
}

checkOutput(true);
}

@Override
public String getExpected() {
logExpected("calling C4.testMethod");
logExpected("inside C4.interfaceMethod");
logExpected("inside C3.testMethod");
logExpected("called C4.testMethod");
return super.getExpected();
}
}
Expand Up @@ -21,23 +21,22 @@
# #
# @authors Andrew Dinn # @authors Andrew Dinn
# #
# Test for bug reported by Flavia Rainone JIRA BYTEMAN-140 where the Transformer # Test for BYTEMAN-219 to ensure that it is possible to call an interface method
# injection through interfaces was failing to traverse the interface extends hierarchy. # inherited by an abstract class even if the abstract class does not iself

# implement the method. the interface method will always be defined by any
RULE test interface injection without overriding # instantiable subclass so a call to the method should typecheck ands execute
INTERFACE I3 # correctly.
METHOD testMethod(Test) #
HELPER org.jboss.byteman.tests.helpers.Default # in this example C3 is an abstract class which implements interface I4
BIND test : TestInterfaceHierarchy = $1 # but leaves it to its subclass C4 to provide the actual implementation of
IF TRUE # method interfaceMethod. The type checker should still detect that this
DO test.log("I3.testMethod() AT ENTRY"); # method can safely be called on any instance of C3.
ENDRULE


RULE test interface injection with overriding RULE test abstract interface method call
INTERFACE ^I3 CLASS C3
METHOD testMethod(Test) METHOD testMethod(Test)
HELPER org.jboss.byteman.tests.helpers.Default HELPER org.jboss.byteman.tests.helpers.Default
BIND test : TestInterfaceHierarchy = $1 BIND test : TestAbstractInterfaceCall = $1
IF TRUE IF TRUE
DO test.log("^I3.testMethod() AT ENTRY"); DO $0.interfaceMethod(test)
ENDRULE ENDRULE

0 comments on commit 29c9870

Please sign in to comment.