Static verification of interface references

The JVM spec (prior to JDK 6, to keep it simple) implies that static data-flow-based verification is done on methods at class load time, including the parameters to method calls. For object references (pointers) this, as I understand it, assures than the class flowing to a use of a reference either matches the use exactly or can be "widened" to match the use, based on the "widening reference conversions" described in the language spec.
What I can't figure out is that this definition of "widening" does not appear to be applied to interfaces. Rather, "widening" of interfaces appears to be allowed (for static verification, not necessarily source compilation) somewhat blindly. Only if a method is called on an interface and the method is not implemented by the runtime object does an error appear to be generated.
Is this true? If so, is the behavior documented anywhere?

Here is an example of what I'm describing:
package verify;
public class Main
public static void main(String args[]) {
     System.out.println("Hello");
     foo();
     System.out.println("Goodbye");
public static void foo() {
     System.out.println("Entered Main.foo");
     B b = new rB();
     b.methodA();
package verify;
public interface A {
public void methodA();
package verify;
public interface B
// extends A
public void methodB();
package verify;
public class rB implements B {
public void methodA() {
     System.out.println("Inside B.methodA");
public void methodB() {
     System.out.println("Inside B.methodB");
The above is compiled initially with the commented lines included, then the lines are commented out and the two changed files are recompiled.
...> java -verify -Xverify -Xfuture verify.Main
Hello
Entered Main.foo
Exception in thread "main" java.lang.IncompatibleClassChangeError: class verify.rB does not implement interface verify.A
     at verify.Main.foo(Main.java:12)
     at verify.Main.main(Main.java:6)
As can be seen, the Main class loads successfully and the method foo is successfully invoked. No error is detected until the call to methodA is attempted.
The "b.methodA();" statement is compiled as an invokeinterface on verify.A.methodA, but when Main is loaded and method foo invoked the variable b cannot be widened to an A. This is easily determined by static class flow analysis, and would most certainly result in a VerifyError if classes were involved rather than interfaces. Why is the class even allowed to begin execution?

Similar Messages

  • Use of static refrence of interface

    Hi friends,
    One of my program i have got a doubt. I just want to know that what is the use of static refernce of interface. I am just giving sample code. any body could tell me how is it possible?
    public interface X{
    public void m1();
    public void m2();
    I don't know where this interface has been implemented. I taken the assumption that inteface has been implemented by the Class Y.
    Now in other class I am just creating static reference of the interface as below.
    Class B{
    static X x1;
    x1.m1(); // is valid code?
    if i is valid code, what is the purpose of this? If call method x1.m1() which method will collected?
    I am in the troble? any help would apriciated.
    Thanks in advance.
    regards & thanks.
    vijaysekhar.vn

    [ code ] [ / code ]
    public interface X{
    public void m1();
    public void m2();>
    Class B{
    static X x1;
    x1.m1(); // is valid code?
    if i is valid code, Static has nothing to do with it. As for whether it is valid code, what does your compiler tell you?
    what is the purpose of this?To have class B use functionality without depending on knowing the concrete type implementing interface X.
    If
    call method x1.m1() which method will collected?Be called, you mean? The m1 in the concrete implementing class of the object x1 is pointing to. Say you have two implementations of interface X: Y and Z. If x1 was initialized with a new Y(), Y's m1. If x1 was initialized with a new Z(), Z's m1.
    I am in the troble? Does it feel like you are? :-)

  • Support for SWF Verification in the reference implementation server

    The Server for Protected Streaming provides a way to configure a whitelist of allowed SWF hashes.  However, from what I can tell, the reference implementation server does not have this capability.  Any suggestions on how to implement SWF Verification in the reference implementation server ?

    To use SWF whitelists with the Reference Implementation, set the SWF  whitelist in a policy, and use that policy when packaging the content.  When issuing a license, the Reference Implementation will use whatever  restrictions were specified in the policy at packaging time.  Alternatively, since the Reference Implementation ships with source  code, you can modify the server so you can specify the SWF whitelist  information at the time the license is generated.

  • Static methods in interfaces

    Java cognoscenti,
    Anyone know why I can't declare a method as static in an interface, but I can in an abstract class. Surely, semantically it's the same - defering the implementation of a static method, not an abstract class and an interface. By the way, I'm using JDK 1.2.2 if that makes a difference

    No, it's not the same. You are not "defering the
    implementation of a static method" because static
    methods are never polymorphic.
    Static methods cannot be abstract for this reason, and
    only abstract methods are allowed in interfaces.I didnt't know that. I thought that - because you can override static methods and you can call them onto an actual instance the method binding would be done at run-time, not at compile-time. So I was trying to prove you wrong, but you are correct !
    A short summary of what I've learnt so far:
    - interfaces cannot contain static methods
    - abstract classes cannot contain abstract static methods
    - static methods can be overriden, but they are not polymorphic; this means that the compiler decides which method to call at compile-time.
    /* output
    SuperClass.someMethod()
    SubClass.someMethod()
    SuperClass.someMethod()
    SuperClass.someMethod()
    SubClass.someMethod()
    SubClass.someMethod()
    SuperClass.someMethod()
    public class Test {
      public final static void main(String[] args) {
          // output: SuperClass.someMethod()
          new SuperClass().someMethod();
          // output: SubClass.someMethod()
          new SubClass().someMethod();
          // output: 2x SuperClass.someMethod()
          SuperClass someClass1 = new SubClass();
          someClass1.someMethod();
          showSuper(someClass1);
          // output: 2x SubClass.someMethod()
          SubClass someClass2 = new SubClass();
          someClass2.someMethod();
          showSub(someClass2);
          showSuper(someClass2); // SuperClass.someMethod()
      public final static void showSuper(SuperClass c) {
            c.someMethod();
      public final static void showSub(SubClass c) {
            c.someMethod();
    class SuperClass {
      public static void someMethod() {
        System.out.println("SuperClass.someMethod()");
    class SubClass extends SuperClass {
      public static void someMethod() {
        System.out.println("SubClass.someMethod()");

  • Static methods in interface (Yes, once again!)

    I know there has been many questions about why static methods in interfaces are not allowed. I know it is forbidden by the JLS. But does anyone know the exact reason for this? Is it just a design issue or are there technical difficulties with allowing it?
    I can't think of any reason that it should be impossible to allow static methods in interfaces. I don't even think it would be very difficult to do. More importantly, it could probably be done without breaking existing code and existing JVMs (not too sure about the last one).
    So once again: Was the choice of not allowing static methods in interfaces a design choice or a technical choice?

    A better example of what you are suggesting is surely ...
    interface i {
        static void one();
    class a implements i {
        static void one() {
            // do something
    class b implements i {
        static void one() {
            // do something else
    }What would be the point of ever doing this?
    You cant call i.one() as the method doesn't exist without an instance of an implementing class.
    To actually ever be able to use that method you would effectively be casting an INSTANCE of a or b -> i. If you have an instance of an a or b then there is absolutely no reason for that method to be static.
    If you wanted to implement some sort of class (ie static) behaviour then class a could call its own internal static method from within the 'one' method.
    To get right to the point ... there isn't one. If it gets added to the language (and I can't see it in my wildest dreams) then Sun have lost their marbles, surely?
    Unless someone can give a good example of when it might be correct and useful to do so? I can't even see how it would be a convenience as it is completely unusable, no?

  • Access to class-attribute by Interface-reference

    Hi OO-Gurus,
    I use an implementation of BADI ME_PROCESS_REQ_CUST to fill and handle user-defined fields in the MM-Purchase-Requisition, method IF_EX_ME_PROCESS_REQ_CUST~OPEN.
    There I  use a reference variable which refers to an interface (type ref to IF_PURCHASE_REQUISITION_ITEM) to access the item-object. My problem is that I need to have access to the class-attribute my_state. The corresponding class lcl_req_item is defined locally (LMEREQF01). So I can’t use  a reference variable with reference to this class (so widening cast using the interface-reference is not possible) .. Does anyone know a trick how to access the class-attribute anyway?
    Coding:
      data:  l_item_list       TYPE MMPUR_REQUISITION_ITEMS,
               l_item             TYPE MMPUR_REQUISITION_ITEM,
               l_item_akt       TYPE mereq_item,
               l_item_ref        TYPE ref to IF_PURCHASE_REQUISITION_ITEM. 
      l_item_list = im_header->get_items().
      loop at l_item_list into l_item.
        l_item_akt = l_item-item->get_data( ).
        l_item_ref = l_item-item.
      endloop.
    (Debugging the code, I manage by doubleclicking the fieldcontent of l_item_ref (e.g ) to show the content of the class-attribute my_state. This works only if the field “Interface” in the Debugger is empty because then I see the attributes of the class. If the field Interface is filled with “IF_PURCHASE_REQUISITION_ITEM”, there aren’t any attributes shown.)
    Thanks in advance for your kind help!!
    Nicole

    Hello Nicole
    The following sample coding shows you how to solve your problem. Please do not ask me how I came across this solution.
    However, if you are studying it carefully you may stumble across a most beautiful property of field-symbols as I did.
    METHOD if_ex_me_process_req_cust~open.
      DATA: l_item_list TYPE mmpur_requisition_items,
      l_item TYPE mmpur_requisition_item,
      l_item_akt TYPE mereq_item,
      l_item_ref TYPE REF TO if_purchase_requisition_item.
      DATA:
        ld_attr         TYPE string,
        lo_obj          TYPE REF TO object.
      FIELD-SYMBOLS:
        <lo_lcl>        TYPE ANY,
        <ls_item>       TYPE mereq_item,
        <ls_itemx>      TYPE mereq_itemx.
      l_item_list = im_header->get_items( ).
      LOOP AT l_item_list INTO l_item.
        l_item_akt = l_item-item->get_data( ).
        l_item_ref = l_item-item.
        lo_obj     ?= l_item-item.  " casting to root object !!!!!
        ld_attr = 'MY_STATE'.
        ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.
        ld_attr = 'MY_STATE->ITEM'.
        ASSIGN lo_obj->(ld_attr) TO <ls_item>.
    "    ASSIGN l_item_ref->(ld_attr) TO <ls_item>.  " does not work...
        ld_attr = 'MY_STATE->ITEMX'.
        ASSIGN lo_obj->(ld_attr) TO <ls_itemx>.
      ENDLOOP.
      " NOTE: data definition of local class lcl_req_item_state (fg MEREQ)
    **    DATA:  item           TYPE mereq_item,
    **           itemx          TYPE mereq_itemx,
    **           header         TYPE REF TO lcl_req_header,
    **           ref_item       TYPE REF TO lcl_req_item,
    **           acct_container TYPE REF TO lcl_acct_container,
    **           source         TYPE REF TO cl_source_of_supply_mm,
    **           release_state  TYPE REF TO cl_release_state_mm,
    **           text_manager   TYPE REF TO lcl_text_manager,
    **           bom            TYPE REF TO lcl_bom,
    **           funds_mgt_active TYPE mmpur_bool VALUE mmpur_no,
    **           aktyp          TYPE aktyp,
    **           no_auth        TYPE mmpur_bool VALUE mmpur_no,
    **           release_op     type mmpur_bool value mmpur_no,
    **           persistent     TYPE mmpur_bool VALUE mmpur_no,
    **           checked        TYPE mmpur_bool VALUE mmpur_no,
    **           manual_configuration TYPE mmpur_bool,
    **           input_buffer_changed TYPE mmpur_bool VALUE mmpur_no,
    **           changed        TYPE mmpur_bool,
    **           broken_rules   TYPE lty_mask,
    **           referenced_rules TYPE lty_mask,
    **           chp_changes    TYPE mmchp_chp_list,
    **           dcm_manager    TYPE REF TO if_revision_manager_dcm,
    **           "DCM Retrofit
    **           rel_state_after_release TYPE REF TO cl_release_state_mm,
    **           "DCM Retrofit
    **           chdoc_container TYPE REF TO lcl_chdoc_container,
    **           "DCM Retrofit
    **           service_changed TYPE mmpur_bool,
    **           "DCM Retrofit
    **           determinants   TYPE lty_item_determinants.
    ENDMETHOD.
    Regards
      Uwe

  • 1000v Removed Interface Reference

    Cisco Support,
    We recently swapped out 1GB interfaces in our ESX server and replaced them w/10GB cards.  When we did that, the interface IDs presented to the 1000v changed.  References to the removed interfaces still appeared when the "show port-channel sum" command was issued.  I managed to delete all but one of the unused port-channels which referenced the stale interface names.  Unfortunately, one of the interfaces is associated w/a port-channel that is actually in use (see below) and I can't delete it.  Is there a way to get rid of this stale interface reference?  Granted it isn't doing anything, but it looks sloppy.  Since the port-channel IDs are generated automatically, I can't just shuffle stuff around (at least I don't know a way of doing so).
    Running version 4.2(1)SV1(4a).
    Thanks in advance.
    -Erik
    1000v# sho port-channel sum
    Flags:  D - Down        P - Up in port-channel (members)
            I - Individual  H - Hot-standby (LACP only)
            s - Suspended   r - Module-removed
            S - Switched    R - Routed
            U - Up (port-channel)
    Group Port-       Type     Protocol  Member Ports
          Channel
    7     Po7(SU)     Eth      LACP      Eth6/3(P)    Eth6/5(P)    
    8     Po8(SU)     Eth      LACP      Eth7/3(P)    Eth7/5(P)    
    9     Po9(SU)     Eth      LACP      Eth3/3(P)    Eth3/5(P)    Eth3/7(r)  <-------------------

    Hey Erik,
    It is CSCua93737: Port-channel has Ghost entries even after removing ports from N1K setup
    You can view the defect using this link 
    https://tools.cisco.com/bugsearch/bug/CSCua93737
    Workaround:
    1. Create a new port-profile and associate new uplink interface to it.
    2. Associate active ports to the new port-profile so that there is a new port-channel created with active uplink ports.
    3. Delete the old port-channel so that all the ghost interfaces would be removed along with it. If you wish to use the same port-profile for all uplink ports, then you can move the uplink ports to the old port-profile one by one so that a new port-channel will be created using the same old port-profile.
    The defect is resolved in SV2(1.1).
    Thanks,
    Joe

  • Doubt in interface reference

    Select two correct statements about the code given below?
    class A{}
    class B extends A implements E{} //line 1
    class C extends A{}
    class D extends B{}
    interface E{}
    class Question07 {
    public static void main(String[] args) {
    A a = new D(); //line 2
    C c = new C(); //line 3
    E e = (E)a; //line 4
    B b = e; //line 5
    }Options
    a. The code compiles without error and runs fine
    b. Compilation error on line 1 because interface E is not yet declared (forward-referencing)
    c. Compilation error on line 4 because class A does not implement interface E
    d. The cast on line 4 is mandatory
    e. The cast on line 5 is not mandatory
    the answer is a,d,e three answers ! all answers understood except d option
    how we can make E reference with casting A , and A is not implement E !!!
    help me please
    Message was edited by:
    eaaje
    Message was edited by:
    eaaje

    The type of variable a is A. Since A does not implement E, to assign a to a variable of type E you must cast it.

  • Why not to use static methods in interfaces?

    why?

    Because static methods are always attached to a particular class -- not an object. So object polymorphism (which is what interfaces are good for) won't help. Now, what you can do is say that subclasses must implement a method that looks an awful lot like a static method, in that it doesn't depend on object state.
    This bugged me, and it still bugs me a little bit in that I have to instantiate an object of a type in order to call these pseudo-static methods. When the pseudo-static methods tell the user how to initialize the object, you get a bit of a chicken-and-egg problem.

  • No static methods for Interfaces ?

    Hi,
    I was going though some documentation about the interfaces and it says that, an interface methods must not be static.
    Can someone please explain or direct me in the direction which tell me why the internet methods cannot be static.
    Thanx.
    Mel

    Defining a static method in a interface would be useless, since static methods can't be executed with dynamic binding. You'd have to know the name of the implementing class of the interface at compile time to call it, which would negate the need for an interface.
    For more details google it, that question has been asked thousands of times.

  • Static methods inside interfaces

    Why they are not allowed? Such methods would be very helpful in some cases. I speak, of course, about method declaration, not method definition.

    Ok , now I understand the problem. Thanks.
    And it's also impossible to override a staticmethod.
    Actually, it is very possible.Nope. That's hiding (or is it shadowing?), not overriding.
    The thing is, it only makes sense to have methods in an interface that can be overridden--by the JLS' definition of overriding--that is, where the particular method implementation that gets invoked is determined at runtime.
    Since static method invocatinos are compile-time bound, there's no reason for them to be in an interface--or indeed abstract at all, whether in an interface or abstract class.

  • Ipv4 from dhcp, ipv6 static on single interface eth0

    Hi,
    pls help me understand or solve my problem with my network setup.
    I had ipv4 ip address assigned dynamically and ipv6 set statically, both via netcfg and everything worked without problem.
    This is my netcfg config:
    CONNECTION='ethernet'
    DESCRIPTION='A basic dhcp ethernet connection using iproute'
    INTERFACE='eth0'
    IP='dhcp'
    PRE_UP='ethtool -s eth0 wol g'
    PRE_DOWN='ethtool -s eth0 wol g'
    ## for IPv6 autoconfiguration
    #IP6='stateless'
    ## for DHCPv6
    IP6='static'
    ADDR6=(2002:54f2:xxxx:1::2/64)
    GATEWAY6=2002:54f2:xxxx:1::1
    But someday I received error when booting up and also when I try to start profile manualy:
    /etc/rc.d/net-profiles start
    :: eth0 up
    RTNETLINK answers: File exists
    Adding gateway 2002:54f2:xxxx:1::1 failed
    No profile started.
    I found that I can't have two gateways on one interface, but until now there's no problem.
    When I disabled GATEWAY6 line from config, eth0 profile can be started but ipv6 connectivity didn't works.
    I tried set ipv6 to stateless that works, but after some time not more that 5min network connection resets and after recovery in couple of seconds only ipv4 works.
    Where's a problem? What can I do to achieve same setup I had before some update last week?
    Thanks

    houmles wrote:I found that I can't have two gateways on one interface, but until now there's no problem.
    I suspect it's a problem with that; I've noticed this problem as well.
    When trying to add multiple default gateways with iproute2 (ie, `ip r a default via xxx:xxx:xxx::xxxx`) it errors with the error you've mentioned. I'm not sure if this is a kernel bug, iproute2 bug, or not a bug at all.
    Having multiple default IPv4 gateways works fine.
    I believe netcfg doesn't check for an existing gateway and delete it first (or use `ip r r` instead or `ip r a`) before adding the one; but I haven't checked the code so I could be wrong.
    EDIT:
    OK, I couldn't resist looking at the code, and it indeed does a 'dumb' addition of the gateway:
    112 if [[ -n "$GATEWAY" ]]; then
    113 report_debug ethernet_iproute_up ip route add default via "$GATEWAY" dev "$INTERFACE"
    114 if ! ip route add default via "$GATEWAY" dev "$INTERFACE"; then
    115 report_iproute "Adding gateway $GATEWAY failed"
    116 fi
    117 fi
    I'm looking at making a patch now. Patch and bug report: https://bugs.archlinux.org/task/29480
    Last edited by fukawi2 (2012-04-16 01:00:09)

  • Inner static class implementing interface

    Hello,
    I have a sample program to test on reflections. here the code goes
    import java.lang.reflect.*;
    import java.awt.*;
    import java.lang.*;
    import java.io.*;
    public class SampleName {
       public static void main(String[] args) {
          NewClass b = new NewClass();
           System.out.println("Calling printModifiers");
           printModifiers(b);
             System.out.println("Calling printInterfaces");
           printInterfaces(b);
       static void printModifiers(Object obj){
              Class cl = obj.getClass();
              int mod = cl.getModifiers();
              if(Modifier.isPublic(mod ))
                   System.out.println("Public");
              if(Modifier.isPrivate(mod ))
                   System.out.println("Private");
              if(Modifier.isFinal(mod ))
                   System.out.println("Final");
              if(Modifier.isStatic(mod ))
                   System.out.println("Static");
              if(Modifier.isAbstract(mod ))
                   System.out.println("Abstract");
       static void printInterfaces(Object o) {
              Class c = o.getClass();
              String str = c.getName();
              System.out.println("name  " +str);
              Class[]  theInterfaces= c.getInterfaces();
              if(theInterfaces.length ==0)
                   System.out.println("no interfaces here ");
              else
                   for(int counter = 0; counter<theInterfaces.length;counter++)
                             String interfaceName = theInterfaces[counter].getName();
                             System.out.println("Interface Name :- " +interfaceName);
    static class NewClass implements newInterface {
    }i have an interface in t same folder as
    public interface newInterface
    }i get an error as below while compiling this java code
    SampleName.java:54: cannot resolve symbol
    symbol  : class newInterface
    location: class SampleName.NewClass
    static class NewClass implements newInterface {
                                      ^
    1 errorplease explain me what is the fault i am making and how can it be resolved.
    tnx

    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    The Gateway to Classpath Nirvana
    Setting the class path (Windows)
    How Classes are Found

  • CM Open Interface - reference back to original bank statement line

    we are using Open Interface for our bank reconciliation. we found that, the API APPS.CE_999_PKG.clear always send us the Open Interface Transaction amount as the cleared amount, and we have no visibility to the amount in the bank statement line.
    eg:
    bank statement line is $100
    if a user manually reconcile this line with an open interface transaction line with amount $200, the status will changed to reconciled and the cleared amount is $200.
    the cleared amount passed through the API to our customize program also $200.
    how can we get the amount $100?
    we are doing some GL posting for the cleared amount. getting $200 will caused us to do over post, as the amount we received only $100 (bank statement line amount)

    Hi All,
    I found this article, which explains about the bank statement mappings.
    *Mapping BAI2, SWIFT Bank Statement Format Masking: BANK_ACCOUNT_NUM, BANK_TRX_NUMBER, BANK_ACCOUNT_TEXT, Agent Bank account number And Others [ID 752532.1]*
    Based on this I defined a new bank statment mapping by coping the existing BAI2 mapping.
    The only change I had to do was to change the position of the BANK_TRX_NUMBER to -2 and my problem got resolved.
    Below is the question and answer as per the document.
    Q2: Why following BAI2 datafile needs bank statement mapping as:
    BANK_TRX_NUMBER 16 -2 and not -1?
    16,581,156500,Z,813009392186700,000000002004/
    A2:
    The bank statement mapping you give to populate depends on where the BANK_TRX_NUMBER is in the data file: Example:
    Rec 16 structure is as follows:
    16,<transaction code>,<amount>,<funds type>,<bank ref #>,<customer ref #>,<text>/
    In the rec:16,581,156500,Z,813009392186700,000000002004/
    while the NUMBER appears to be -1 position however the text is assumed missing here and hence the
    BANK_TRX_NUMBER 16 -2 will work.
    Thanks and Regards,
    MPH

  • E-Tester Script Programming Interface Reference Guide   - question

    Hello,
    I just came across this question posted as a Comment for this Knowledge Base document http://qazone.empirix.com/entry.jspa?externalID=34&categoryID=18, so I am adding it to the Forums for additional visibility and replies
    Author: Wegener, Posted: Jul 23, 2007 11:47 AM
    To get the current workspace in a Job Scheduler job I used the following code from the reference
    Private Sub ThisJob_JobBegin()
    Dim location
    location = application.currentResult.workspace
    End Sub
    As a result the value of the variable location changed from Empty to "".
    What can be the reason for this failure?

    We had a similar problem. You actually need to do this in job end or script end event. The application.currentResult object does not have any data until the end of a test.
    I hope this is helpful.

Maybe you are looking for