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

  • Home
  • SEARCH
  • 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 996637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:54:30+00:00 2026-05-16T06:54:30+00:00

When debugging Java code, Eclipse has a feature that allows it to find all

  • 0

When debugging Java code, Eclipse has a feature that allows it to find all instances of a given type (via context menu in the Variables window). Is there any way to filter these programatically? For instance, I want all instances of class FieldInstruction where

the_instance.getType().getName().equals("somestring")  

Evaluates to true.

As I am trying to debug code that is already supposed to be enumerating all the instances, just creating my own code the walk the tree structure where the classes exist kind of defeats the purpose. I’d really like to be able to do this filtering through the Display or Expressions windows.

  • 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-05-16T06:54:31+00:00Added an answer on May 16, 2026 at 6:54 am

    I ended up creating a rather hacky “InstanceRegistry” class. In the constructor of each class type I want to track, I put

    InstanceRegistry.register(this);
    

    This even takes care of “registering” the instance under all super classes and interfaces.

    To iterate over the instances (can even be done in the Eclipse Display window):

    for(Object instance : InstanceRegistry.getInstances(FieldInstruction.class)) {
        //do something
    }
    

    The source code of class InstanceRegistry:

    import java.lang.ref.WeakReference;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Iterator;
    
    public class InstanceRegistry {
        private InstanceRegistry() {}
    
        private static HashMap<Class<?>, HashSet<WeakReference<?>>> instances = new HashMap<Class<?>, HashSet<WeakReference<?>>>();
    
        public static <T> Iterable<T> getInstances(final Class<T> type) {
            return new Iterable<T>() {
                public Iterator<T> iterator() {
                    return new Iterator<T>() {
                        Iterator<WeakReference<?>> it = instances.get(type).iterator();
                        T item = find();
    
                        {
                            System.gc();
                        }
    
                        public boolean hasNext() {
                            return item != null;
                        }
    
                        private T find() {
                            WeakReference<T> fi;
                            while(it.hasNext()) {
                                fi = (WeakReference<T>) it.next();
                                if(fi.get() != null)
                                    return fi.get();
                            }
                            return null;
                        }
    
                        public T next() {
                            T ret = item;
                            item = find();
                            return ret;
                        }
    
                        public void remove() {
                            throw new UnsupportedOperationException();
                        }
                    };
                }
            };
        }
    
        private static void put(Class<?> type, WeakReference<?> instance) {
            HashSet<WeakReference<?>> list = instances.get(type);
            if(list == null) {
                list = new HashSet<WeakReference<?>>();
                instances.put(type, list);
            }
            list.add(instance);
        }
    
        public static void register(Object instance) {
            WeakReference<Object> inst = new WeakReference<Object>(instance);
            Class<?> c = instance.getClass();
            do {
                put(c, inst);
                for(Class<?> ci : c.getInterfaces()) {
                    put(ci, inst);
                }
                c = c.getSuperclass();
            } while(c != Object.class);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While debugging Java code that uses reflection in Eclipse, some times I need to
When debugging Java code in Eclipse, is there any way to find which method
When debugging Java code using Eclipse, for collection variables, I saw the modcount member.
when debugging java code, in the stack trace, I noticed that something in the
I'm debugging the JAVA code in Eclipse. Let's say there are 2 breakpoints inside
I'm debugging some Java code that uses Apache POI to pull data out of
I have Eclipse Helios SR1 installed on Windows XP. I am writing/debugging Java code
I'm developing a code in Eclipse (java). While debugging the code, I used a
I'm having a strange problem when debugging some java code with eclipse (Version: Helios
In Eclipse (Ganymede) I'm debugging some code that uses Apache Commons HttpClient and would

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.