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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:28:32+00:00 2026-05-12T21:28:32+00:00

Sometimes I seem to be quite inefficient. When I was nearly finished typing this,

  • 0

Sometimes I seem to be quite inefficient. When I was nearly finished typing this, I managed to find the appropriate bug report at Sun. I then thought well, might as well post it, having the screenshot and all. Answer follows.

I know, “SELECT isn’t broken”, and it’s always my fault. But here, I really don’t get why it should be. My code snippet:

List<IGraphEdge> rgSrc = this._rgGetPath();
List<IGraphEdge> rgDst = new ArrayList<IGraphEdge>(rgSrc.size());
Collections.copy(rgDst, rgSrc);

This throws an IndexOutOfBoundException with the message

java.lang.IndexOutOfBoundsException: Source does not fit in dest
        at java.util.Collections.copy(Collections.java:548)

In the debugger, when I step into Collections.copy, the two ArrayList instances look like this:

Debugger view http://static.theuprightape.net/ql/img/debugger.png

So, there’s the capacity in dest to hold that one element from src, although, naturally, the size of dest is still 0, after all, this is what I want to change by calling copy().

Looking at the source code of the OpenJDK implementation, it’s clear why the error is thrown:

public static <T> void copy(List<? super T> dest, List<? extends T> src) {
    int srcSize = src.size();
    if (srcSize > dest.size())
        throw new IndexOutOfBoundsException("Source does not fit in dest");

So please tell me, is that a bug, or what am I doing wrong?

  • 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-12T21:28:32+00:00Added an answer on May 12, 2026 at 9:28 pm

    It’s not looking at the capacity, it’s looking at the size. That is, the destination should contain elements, which are to be overwritten by the source list.

    I’ve never run into a case where this would be useful. Usually what you want is a copy constructor in one of the List implementations, or the addAll method of the Collection interface.

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

Sidebar

Related Questions

I have this chronic issue with iPhone UI development where views sometimes seem to
I've had this setup, but it didn't seem quite right. How would you improve
I know this may seem quite basic to geeks. But I want to make
tried to research on that but sometimes I seem to lack some googling skills...
Sometimes when using Visual Studio it displays a prompt with a filename: This file
Sometimes I heard people discussing about the start-up time for Java. It seems this
Sorry that this may seem like a rookie question, but it's a real pain
We have a web application which sometimes (quite rarely, several times a day) gives
Sometimes I seem to get 0, which means that all I got was a
I am using IETester for testing web sites with IE. I find it quite

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.