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 8124073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:21:29+00:00 2026-06-06T06:21:29+00:00

I had a bunch of table views that had code duplicated in them. They

  • 0

I had a bunch of table views that had code duplicated in them. They used to directly inherit the AbstractView class. So then I made them inherit AbstractListView(Which would in it’s turn inherit from AbstractView) which would be the new class holding all the common properties for these tables.

Since I made that change this loop is behaving oddly:

for (AbstractViewPanel view : registeredViews) {
        view.modelPropertyChange(evt);
}

Here is the arrayList: registeredViews:

private ArrayList<AbstractViewPanel> registeredViews;

I’ve run the debugger and the registeredViews arrayList has all of the views including the table ones. For some reason it stalls at the last directly inherited view in the collection and completely skips them.

All my views used to directly inherit:

public class someView extends AbstractViewPanel

Now since my change some of the views are like this:

public class someOtherView extends AbstractListView

Here’s AbstractListView:

public abstract class AbstractListView extends AbstractViewPanel

Here’s AbstractViewPanel

public abstract class AbstractViewPanel extends JPanel {


public abstract void modelPropertyChange(PropertyChangeEvent evt);

}

The loop is simply not going over anything that inherits AbstractListView, yet I would assume that all of the views in the end are of type AbstractView.

UPDATE
I’ve managed to find a workaround it simply involves changing the loop:

for (int i = 0; i < registeredViews.size(); i++) 
{
        registeredViews.get(i).modelPropertyChange(evt);
}

I would like to know though why the foreach style loop was giving me headaches.

  • 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-06T06:21:32+00:00Added an answer on June 6, 2026 at 6:21 am

    For reference, I’ve created a skeleton sscce of your design. List<E> implements Iterable<E>, so there’s no a priori reason your foreach should fail. Here are a few thing to check:

    • Verify that GUI objects are constructed and manipulated only on the event dispatch thread.

    • Verify that you are not overlooking a ClassCastException when an instance of SomeOtherView is retrieved from the List.

    • As the List is heterogenous, see Bloch, Effective Java 2nd ed., Item 29: Consider typesafe heterogeneous containers.” The pattern is mentioned here.

    • Addendum: Would you not see a concurrent modification exception in that case?

      No, ConcurrentModificationException “does not always indicate that an object has been concurrently modified by a different thread.” The exception is thrown if the “list has been structurally modified” outside of the iterator, on a best-effort basis. More likely, the failing iterator was obtained after adding some views but before adding others. This could happen unexpectedly if the list were constructed on the initial thread and iterated on the EDT.

    SSCCE:

    import java.awt.EventQueue;
    import java.awt.GridLayout;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    public class Test {
    
        private List<AbstractViewPanel> registeredViews;
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new Test().init();
                }
            });
        }
    
        private void init() {
            JFrame f = new JFrame("Test");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setLayout(new GridLayout(0, 1));
    
            registeredViews = new ArrayList<AbstractViewPanel>();
            for (int i = 0; i < 2; i++) {
                registeredViews.add(new SomeView());
                registeredViews.add(new SomeOtherView());
            }
            for (AbstractViewPanel view : registeredViews) {
                f.add(view);
            }
    
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    
        abstract class AbstractViewPanel extends JPanel {
    
            public AbstractViewPanel() {
                add(new JLabel(getClass().toString()));
            }
        }
    
        abstract class AbstractListView extends AbstractViewPanel {
        }
    
        class SomeView extends AbstractViewPanel {
        }
    
        class SomeOtherView extends AbstractListView {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a bunch of code in an activity that displays a running graph
I had a bunch of apps that worked great in iOS 4. None of
If I had a bunch of absolute positioned divs and they overlapped, how would
I had a bunch of controls that I displayed, hid, enabled and disabled based
I had a bunch of bookmark to www.asp.net/learn/, specially the one about data-access and
I've had a bunch of EAGAIN's from trying to fork() or spawning threads, which
I had set up a bunch of NUnit unit tests using the Test connection
Last night I had a script go a bit crazy and create a bunch
Had a page that was working fine. Only change I made was to add
Sorry if this question isn't clear. The short story is that we had someone

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.