Hbase delete遇到的常见异常: Exception in thread "main" java.lang.UnsupportedOperationException

hbase 执行批量删除时出现错误:

 Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:161)
at org.apache.hadoop.hbase.client.HTable.delete(HTable.java:852)

这种异常其实很常见,remove操作不支持,为什么会出现不支持的情况呢?检查代码时发现传参list 是通过Arrays.asList()创建的,

很明显,问题就是这个地方导致的,Arrays.asList()返回是实际上是Arrays类内部的一个实现ArrayList:

   /**
     * @serial include
     */
    private static class ArrayList<E> extends AbstractList<E>
        implements RandomAccess, java.io.Serializable
    {
        private static final long serialVersionUID = -2764017481108945198L;
        private final E[] a;

        ArrayList(E[] array) {
            if (array==null)
                throw new NullPointerException();
            a = array;
        }

        public int size() {
            return a.length;
        }

        public Object[] toArray() {
            return a.clone();
        }

        public <T> T[] toArray(T[] a) {
            int size = size();
            if (a.length < size)
                return Arrays.copyOf(this.a, size,
                                     (Class<? extends T[]>) a.getClass());
            System.arraycopy(this.a, 0, a, 0, size);
            if (a.length > size)
                a[size] = null;
            return a;
        }

        public E get(int index) {
            return a[index];
        }

        public E set(int index, E element) {
            E oldValue = a[index];
            a[index] = element;
            return oldValue;
        }

        public int indexOf(Object o) {
            if (o==null) {
                for (int i=0; i<a.length; i++)
                    if (a[i]==null)
                        return i;
            } else {
                for (int i=0; i<a.length; i++)
                    if (o.equals(a[i]))
                        return i;
            }
            return -1;
        }

        public boolean contains(Object o) {
            return indexOf(o) != -1;
        }
    }

Arrays.ArrayList继承至AbstractList,AbstractList本身是不支持删除操作的,Arrays.ArrayList也没有重现remove方法,因此,如果通过Arrays.asList()创建的ArrayList,如果调用了remove方法,则会出现UnsupportedOperationException异常。

时间: 2024-10-13 16:05:30

Hbase delete遇到的常见异常: Exception in thread "main" java.lang.UnsupportedOperationException的相关文章

dom4j使用xpath报异常 Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext

Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:230 ) at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:207) at org.dom4j.tree.Abstrac

Junit测试出现异常:Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: org.junit.platform.commons.util.

在进行单元测试时,测试出现异常 Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader; 错误就在pom.xml的依赖中,仔细查看控制台输出你会发现IntelliJ IDEA正在尝试使用JUnit5运行我的测试用例. at com.intelli

异常Exception in thread &quot;AWT-EventQueue-XX&quot; java.lang.StackOverflowError

今天太背了,bug不断,检查到最后都会发现自己脑残了,粗心写错,更悲剧的是写错的时候还不提示错. 刚才有遇到一个问题,抛了这个异常Exception in thread "AWT-EventQueue-XX" java.lang.StackOverflowError XX有好几个值,我遇到了2,7,20,其实他们都是一个错,StackOverflowError,对,就是栈溢出,为什么会栈溢出呢?我遇到的问题是我写了一个方法,又自己去调用自己,造成了递归,而这个递归又停不下来,造成了栈溢

【异常】idea执行Main方法出现 Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest

一.异常复现步骤 1)首先得是一个Spring MVC项目 注:Spring Boot项目有内置的web 容器,不会出现该问题 2)main方法存在于使用HttpServletRequest类的类中 3)项目POM中引入有javax.servlet-api坐标或没有 <!-- Servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-ap

2类型转换异常:Exception in thread &quot;main&quot; java.lang.ClassCastException:java.lang.Object cannot be cast to java.lang.Integer

public class TestException {    public static void main(String[] args) {        Object obj = new Integer(1);        int i =(Integer)(obj);        System.out.println(i);                Object object = new Object();        if (object instanceof Integer

Jenkins的slave异常:Exception in thread &quot;main&quot; java.lang.ClassNotFoundException: hudson.remoting.Launcher

当任务分配到slave上执行时,报如下错误: Parsing POMs Established TCP socket on 38257 maven33-agent.jar already up to date maven33-interceptor.jar already up to date maven3-interceptor-commons.jar already up to date [b012ef95d917292e062fe3d70c7a9b01] $ java -cp /var/l

运行jar包时出现异常:Exception in thread &quot;main&quot; java.lang.ExceptionInInitializerError

/usr/local/java/jdk1.8.0_60/bin/java SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/usr/local/jstorm-2.2.1/wait_deploy/test-jstorm-bolt.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar

【异常】Exception in thread &quot;main&quot; java.lang.IllegalArgumentException: Illegal pattern c

在windows上执行的时候,option(“timestampFormat”, “yyyy/MM/dd HH:mm:ss ZZ”)必须带上,不然报错: Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern component: XX. 使用比如:val df1 = spark.read.format("json").option("timestampF

Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: org/apache/hadoop/yarn/util/Apps Hadoop2.6.0编程问题与解决

从hadoop 1.2.1升级到 Hadoop2.6.0,调试写代码,还是遇到一些问题的.这里记录一下,后续如果自己再遇到类似问题,那也好找原因了. 在eclipse里编译运行 WordCount,出现以下错误. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/yarn/util/Apps at java.lang.ClassLoader.defineClass1(Native M