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

removeIf() on List from Arrays.asList() throws UnsupportedOperationException

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      Hi Team,
      I found an undesirable behavior of "default boolean removeIf(Predicate<? super E> filter)" method of java.util.Collection interface.

      1. If the operation is performed over ArrayList data structure by adding elements thru List add() method i.e. "list.add("ABC");", execution like below works fine.
      List<String> list = new ArrayList<String>();
      list.add("ABC");
      list.add("BBC");
      list.add("CCD");
      list.removeIf(n -> (n.charAt(0) == 'B'));

      Result: (as expected)
      ABC
      CCD

      2. If list is updated with Array.asList() operation, it throws exception.
      List<String> list = new ArrayList<String>();
      list = Arrays.asList("ABC","BBC","CCD");
              list.removeIf(n -> (n.charAt(0) == 'B'));

      Result: Exception in thread "main" java.lang.UnsupportedOperationException

      REGRESSION : Last worked in version 8u231

      ACTUAL -
      Exception in thread "main" java.lang.UnsupportedOperationException

      FREQUENCY : always


            martin Martin Buchholz
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: