Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:17:03+00:00 2026-06-04T22:17:03+00:00

I’m using the MOP tool for Java ( JavaMOP ) to produce Aspects that

  • 0

I’m using the MOP tool for Java (JavaMOP) to produce Aspects that run in Android.
I’m trying with the HasNext example that simply specifies that a program always calls the hasnext method before the next method of an iterator.

The code of the produced aspect with JavaMOP is:

package mop;
import java.io.*;
import java.util.*;
import javamoprt.*;
import java.lang.ref.*;
import org.aspectj.lang.*;

class HasNextMonitor_Set extends javamoprt.MOPSet {
    protected HasNextMonitor[] elementData;

    public HasNextMonitor_Set(){
        this.size = 0;
        this.elementData = new HasNextMonitor[4];
    }

    public final int size(){
        while(size > 0 && elementData[size-1].MOP_terminated) {
            elementData[--size] = null;
        }
        return size;
    }

    public final boolean add(MOPMonitor e){
        ensureCapacity();
        elementData[size++] = (HasNextMonitor)e;
        return true;
    }

    public final void endObject(int idnum){
        int numAlive = 0;
        for(int i = 0; i < size; i++){
            HasNextMonitor monitor = elementData[i];
            if(!monitor.MOP_terminated){
                monitor.endObject(idnum);
            }
            if(!monitor.MOP_terminated){
                elementData[numAlive++] = monitor;
            }
        }
        for(int i = numAlive; i < size; i++){
            elementData[i] = null;
        }
        size = numAlive;
    }

    public final boolean alive(){
        for(int i = 0; i < size; i++){
            MOPMonitor monitor = elementData[i];
            if(!monitor.MOP_terminated){
                return true;
            }
        }
        return false;
    }

    public final void endObjectAndClean(int idnum){
        int size = this.size;
        this.size = 0;
        for(int i = size - 1; i >= 0; i--){
            MOPMonitor monitor = elementData[i];
            if(monitor != null && !monitor.MOP_terminated){
                monitor.endObject(idnum);
            }
            elementData[i] = null;
        }
        elementData = null;
    }

    public final void ensureCapacity() {
        int oldCapacity = elementData.length;
        if (size + 1 > oldCapacity) {
            cleanup();
        }
        if (size + 1 > oldCapacity) {
            HasNextMonitor[] oldData = elementData;
            int newCapacity = (oldCapacity * 3) / 2 + 1;
            if (newCapacity < size + 1){
                newCapacity = size + 1;
            }
            elementData = Arrays.copyOf(oldData, newCapacity);
        }
    }

    public final void cleanup() {
        int numAlive = 0 ;
        for(int i = 0; i < size; i++){
            HasNextMonitor monitor = (HasNextMonitor)elementData[i];
            if(!monitor.MOP_terminated){
                elementData[numAlive] = monitor;
                numAlive++;
            }
        }
        for(int i = numAlive; i < size; i++){
            elementData[i] = null;
        }
        size = numAlive;
    }

    public final void event_hasnext(Iterator i) {
        int numAlive = 0 ;
        for(int i_1 = 0; i_1 < this.size; i_1++){
            HasNextMonitor monitor = (HasNextMonitor)this.elementData[i_1];
            if(!monitor.MOP_terminated){
                elementData[numAlive] = monitor;
                numAlive++;

                monitor.Prop_1_event_hasnext(i);
                if(monitor.Prop_1_Category_fail) {
                    monitor.Prop_1_handler_fail(i);
                }
            }
        }
        for(int i_1 = numAlive; i_1 < this.size; i_1++){
            this.elementData[i_1] = null;
        }
        size = numAlive;
    }

    public final void event_next(Iterator i) {
        int numAlive = 0 ;
        for(int i_1 = 0; i_1 < this.size; i_1++){
            HasNextMonitor monitor = (HasNextMonitor)this.elementData[i_1];
            if(!monitor.MOP_terminated){
                elementData[numAlive] = monitor;
                numAlive++;

                monitor.Prop_1_event_next(i);
                if(monitor.Prop_1_Category_fail) {
                    monitor.Prop_1_handler_fail(i);
                }
            }
        }
        for(int i_1 = numAlive; i_1 < this.size; i_1++){
            this.elementData[i_1] = null;
        }
        size = numAlive;
    }
}

class HasNextMonitor extends javamoprt.MOPMonitor implements Cloneable, javamoprt.MOPObject {
    public Object clone() {
        try {
            HasNextMonitor ret = (HasNextMonitor) super.clone();
            return ret;
        }
        catch (CloneNotSupportedException e) {
            throw new InternalError(e.toString());
        }
    }

    int Prop_1_state;
    static final int Prop_1_transition_hasnext[] = {1, 1, 2};;
    static final int Prop_1_transition_next[] = {2, 0, 2};;

    boolean Prop_1_Category_fail = false;

    public HasNextMonitor () {
        Prop_1_state = 0;

    }

    public final void Prop_1_event_hasnext(Iterator i) {
        MOP_lastevent = 0;

        Prop_1_state = Prop_1_transition_hasnext[Prop_1_state];
        Prop_1_Category_fail = Prop_1_state == 2;
    }

    public final void Prop_1_event_next(Iterator i) {
        MOP_lastevent = 1;

        Prop_1_state = Prop_1_transition_next[Prop_1_state];
        Prop_1_Category_fail = Prop_1_state == 2;
    }

    public final void Prop_1_handler_fail (Iterator i){
        {
            System.err.println("! hasNext() has not been called" + " before calling next() for an" + " iterator");
            this.reset();
        }

    }

    public final void reset() {
        MOP_lastevent = -1;
        Prop_1_state = 0;
        Prop_1_Category_fail = false;
    }

    public javamoprt.ref.MOPWeakReference MOPRef_i;

    //alive_parameters_0 = [Iterator i]
    public boolean alive_parameters_0 = true;

    public final void endObject(int idnum){
        switch(idnum){
            case 0:
            alive_parameters_0 = false;
            break;
        }
        switch(MOP_lastevent) {
            case -1:
            return;
            case 0:
            //hasnext
            //alive_i
            if(!(alive_parameters_0)){
                MOP_terminated = true;
                return;
            }
            break;

            case 1:
            //next
            //alive_i
            if(!(alive_parameters_0)){
                MOP_terminated = true;
                return;
            }
            break;

        }
        return;
    }

}

public aspect HasNextMonitorAspect implements javamoprt.MOPObject {
    javamoprt.map.MOPMapManager HasNextMapManager;
    public HasNextMonitorAspect(){
        HasNextMapManager = new javamoprt.map.MOPMapManager();
        HasNextMapManager.start();
    }

    // Declarations for the Lock
    static Object HasNext_MOPLock = new Object();

    static boolean HasNext_activated = false;

    // Declarations for Indexing Trees
    static javamoprt.map.MOPBasicRefMapOfMonitor HasNext_i_Map = new javamoprt.map.MOPBasicRefMapOfMonitor(0);
    static javamoprt.ref.MOPWeakReference HasNext_i_Map_cachekey_0 = javamoprt.map.MOPBasicRefMapOfMonitor.NULRef;
    static HasNextMonitor HasNext_i_Map_cachenode = null;

    // Trees for References
    static javamoprt.map.MOPRefMap HasNext_Iterator_RefMap = HasNext_i_Map;

    pointcut MOP_CommonPointCut() : !within(javamoprt.MOPObject+) && !adviceexecution();
    pointcut HasNext_hasnext(Iterator i) : (call(* Iterator.hasNext()) && target(i)) && MOP_CommonPointCut();
    after (Iterator i) : HasNext_hasnext(i) {
    try{
        HasNext_activated = true;
        synchronized(HasNext_MOPLock) {
            HasNextMonitor mainMonitor = null;
            javamoprt.map.MOPMap mainMap = null;
            javamoprt.ref.MOPWeakReference TempRef_i;

            // Cache Retrieval
            if (i == HasNext_i_Map_cachekey_0.get()) {
                TempRef_i = HasNext_i_Map_cachekey_0;

                mainMonitor = HasNext_i_Map_cachenode;
            } else {
                TempRef_i = HasNext_i_Map.getRef(i);
            }

            if (mainMonitor == null) {
                mainMap = HasNext_i_Map;
                mainMonitor = (HasNextMonitor)mainMap.getNode(TempRef_i);

                if (mainMonitor == null) {
                    mainMonitor = new HasNextMonitor();

                    mainMonitor.MOPRef_i = TempRef_i;

                    HasNext_i_Map.putNode(TempRef_i, mainMonitor);
                }

                HasNext_i_Map_cachekey_0 = TempRef_i;
                HasNext_i_Map_cachenode = mainMonitor;
            }

            mainMonitor.Prop_1_event_hasnext(i);
            if(mainMonitor.Prop_1_Category_fail) {
                mainMonitor.Prop_1_handler_fail(i);
            }
        }
        }catch(Exception e){
                    System.out.println("Cause: "+e.getCause().toString());
                    System.out.println("Error:"+e.getLocalizedMessage());
                }
    }

    pointcut HasNext_next(Iterator i) : (call(* Iterator.next()) && target(i)) && MOP_CommonPointCut();
    before (Iterator i) : HasNext_next(i) {
        try{
        HasNext_activated = true;
        synchronized(HasNext_MOPLock) {
            HasNextMonitor mainMonitor = null;
            javamoprt.map.MOPMap mainMap = null;
            javamoprt.ref.MOPWeakReference TempRef_i;

            // Cache Retrieval
            if (i == HasNext_i_Map_cachekey_0.get()) {
                TempRef_i = HasNext_i_Map_cachekey_0;

                mainMonitor = HasNext_i_Map_cachenode;
            } else {
                TempRef_i = HasNext_i_Map.getRef(i);
            }

            if (mainMonitor == null) {
                mainMap = HasNext_i_Map;
                mainMonitor = (HasNextMonitor)mainMap.getNode(TempRef_i);

                if (mainMonitor == null) {
                    mainMonitor = new HasNextMonitor();

                    mainMonitor.MOPRef_i = TempRef_i;

                    HasNext_i_Map.putNode(TempRef_i, mainMonitor);
                }

                HasNext_i_Map_cachekey_0 = TempRef_i;
                HasNext_i_Map_cachenode = mainMonitor;
            }

            mainMonitor.Prop_1_event_next(i);
            if(mainMonitor.Prop_1_Category_fail) {
                mainMonitor.Prop_1_handler_fail(i);
            }
        }
    }catch(Exception e){
                    System.out.println("Cause: "+e.getCause().toString());
                    System.out.println("Error:"+e.getLocalizedMessage());
                }
    }

    after(Iterator i) throwing (Exception e): HasNext_next(i) {
      System.out.println("Threw an exception: " + e);
      }
    after(Iterator i) throwing (Exception e): HasNext_hasnext(i) {
      System.out.println("Threw an exception: " + e);
      }

}

}

The method in my Android project is:

public void method1() {
        Vector<Integer> v = new Vector<Integer>();
        v.add(1);
        v.add(2);
        v.add(3);
        v.add(4);
        Iterator<Integer> i = v.iterator();
        int sum = 0;
        if (i.hasNext()) {
            sum += (Integer) i.next();
            sum += (Integer) i.next();
            sum += (Integer) i.next();
            sum += (Integer) i.next();
        }
        System.out.println("sum: " + sum);
}

After weaving the Android project with the aspect and execute the method, the application throws the following exception:

E/AndroidRuntime(2334): FATAL EXCEPTION: main
E/AndroidRuntime(2334): org.aspectj.lang.NoAspectBoundException: Exception while initializing mop_HasNextMonitorAspect: java.lang.ExceptionInInitializerError
E/AndroidRuntime(2334):     at mop.HasNextMonitorAspect.aspectOf(HasNextMonitorAspect.aj:1)
E/AndroidRuntime(2334):     at com.mopapplication.MOPApplicationActivity.method1(Unknown Source)
E/AndroidRuntime(2334):     at com.mopapplication.MOPApplicationActivity$3.onClick(Unknown Source)
E/AndroidRuntime(2334):     at android.view.View.performClick(View.java:3122)
E/AndroidRuntime(2334):     at android.view.View$PerformClick.run(View.java:11942)
E/AndroidRuntime(2334):     at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(2334):     at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(2334):     at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime(2334):     at android.app.ActivityThread.main(ActivityThread.java:4028)
E/AndroidRuntime(2334):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(2334):     at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime(2334):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
E/AndroidRuntime(2334):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
E/AndroidRuntime(2334):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(2334): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime(2334):     at java.lang.management.ManagementFactory.getOperatingSystemMXBean(ManagementFactory.java:409)
E/AndroidRuntime(2334):     at javamoprt.map.MOPMapManager.<init>(Unknown Source)
E/AndroidRuntime(2334):     at mop.HasNextMonitorAspect.<init>(HasNextMonitorAspect.aj:231)
E/AndroidRuntime(2334):     at mop.HasNextMonitorAspect.ajc$postClinit(HasNextMonitorAspect.aj:1)
E/AndroidRuntime(2334):     at mop.HasNextMonitorAspect.<clinit>(HasNextMonitorAspect.aj:228)
E/AndroidRuntime(2334):     ... 13 more
E/AndroidRuntime(2334): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load management: findLibrary returned null
E/AndroidRuntime(2334):     at java.lang.Runtime.loadLibrary(Runtime.java:425)
E/AndroidRuntime(2334):     at java.lang.System.loadLibrary(System.java:554)
E/AndroidRuntime(2334):     at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
E/AndroidRuntime(2334):     at java.security.AccessController.doPrivileged(AccessController.java:116)
E/AndroidRuntime(2334):     at java.security.AccessController.doPrivileged(AccessController.java:85)
E/AndroidRuntime(2334):     at sun.management.ManagementFactory.<clinit>(ManagementFactory.java:467)
E/AndroidRuntime(2334):     ... 18 more

I know is not a problem of libraries because i’m including the AspectJ, JavaMOP, and Java run-time libraries inside the Android Project (for the Java run-time library i’m including just the necessary classes and packages, not the whole library).

Any idea what is the problem?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:17:05+00:00Added an answer on June 4, 2026 at 10:17 pm

    From the stacktrace we can read that the library you are using is trying to load a “management” library.
    That library is included with sun’s (now Oracle) jdk, but is not part of android.
    I’m guessing you won’t have any luck using this lib in android, because it depends on management stuff like SNMP that is not included in android.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.