Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8197893

Mistaken type check in CheckedEntrySet.toArray

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 11
    • None
    • core-libs

      errorprone reports:

      java/java/util/Collections.java:3819: warning: [IsInstanceOfClass] The argument to Class#isInstance(Object) should not be a Class

                  @SuppressWarnings("unchecked")
                  public Object[] toArray() {
                      Object[] source = s.toArray();

                      /*
                       * Ensure that we don't get an ArrayStoreException even if
                       * s.toArray returns an array of something other than Object
                       */
                      Object[] dest = (CheckedEntry.class.isInstance(
                          source.getClass().getComponentType()) ? source :
                                       new Object[source.length]);

      although the only consequence of the mistake is an extra copy.

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: