Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.2版本 jad命令在jdk低于1.8的环境下异常 #851

Closed
1 task
yinbifen opened this issue Sep 11, 2019 · 2 comments
Closed
1 task

3.1.2版本 jad命令在jdk低于1.8的环境下异常 #851

yinbifen opened this issue Sep 11, 2019 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@yinbifen
Copy link

  • 我已经在 issues 里搜索,没有重复的issue。

环境信息

  • arthas-boot.jar 或者 as.sh 的版本: 3.1.2
  • Arthas 版本: 3.1.2
  • 操作系统版本: win10 1903
  • 目标进程的JVM版本: 1.7.0_80
  • 执行arthas-boot的版本: 1.7.0_80

重现问题的步骤

  1. java -jar arthas-demo.jar
  2. java -jar arthas-boot.jar
  3. jad demo.MathGame

期望的结果

What do you expected from the above steps?

实际运行的结果

实际运行结果,最好有详细的日志,异常栈。尽量贴文本。

01 2019-09-10 18:00:49.435 ERROR [as-command-execute-daemon:arthas] [] [] [] jad: fail to decompile class: demo.MathGame
java.lang.UnsupportedOperationException: null
	at java.util.AbstractList.set(AbstractList.java:132)
	at java.util.AbstractList$ListItr.set(AbstractList.java:426)
	at java.util.Collections.sort(Collections.java:159)
	at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:48)
	at com.taobao.arthas.core.util.Decompiler.decompile(Decompiler.java:60)
	at com.taobao.arthas.core.command.klass100.JadCommand.processExactMatch(JadCommand.java:156)
	at com.taobao.arthas.core.command.klass100.JadCommand.process(JadCommand.java:113)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
	at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
	at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:370)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

@hengyunabc hengyunabc added the bug Something isn't working label Sep 12, 2019
@hengyunabc hengyunabc changed the title jad命令在jdk低于1.8的环境下异常 3.1.2版本 jad命令在jdk低于1.8的环境下异常 Sep 12, 2019
@hengyunabc
Copy link
Collaborator

3.1.2版本里升级了cfr,然后在反编译时用Collections.singletonList创建了一个参数,传递给cfr使用:

        CfrDriver driver = new CfrDriver.Builder().withOptions(options).withOutputSink(mySink).build();
        driver.analyse(Collections.singletonList(classFilePath));

但cfr里调用了Collections.sort来处理这个list ,所以导致出问题。


根本原因是 jdk 6/7 和 jdk8的 Collections.sort 的实现不同导致的。

jdk7下面的实现是:

    public static <T extends Comparable<? super T>> void sort(List<T> list) {
        Object[] a = list.toArray();
        Arrays.sort(a);
        ListIterator<T> i = list.listIterator();
        for (int j=0; j<a.length; j++) {
            i.next();
            i.set((T)a[j]);
        }
    }

这里的i.set((T)a[j]); 要修改 list里的元素。所以抛出了一个UnsupportedOperationException异常。

在jdk8里的实现是:

    public static <T extends Comparable<? super T>> void sort(List<T> list) {
        list.sort(null);
    }

实际上Collections.singletonList 返回的是SingletonList

    public static <T> List<T> singletonList(T o) {
        return new SingletonList<>(o);
    }

它的 sort函数是空的,所以在jdk8下面可以正常工作:

    /**
     * @serial include
     */
    private static class SingletonList<E>
        extends AbstractList<E>
        implements RandomAccess, Serializable {
        @Override
        public void sort(Comparator<? super E> c) {
        }

@vanTryMyBest
Copy link

遇到同样的问题,重新下载新的jar包,现在已经解决了
01 2019-09-19 10:14:10.276 ERROR [as-command-execute-daemon:arthas] [] [] [] jad: fail to decompile class: demo.MathGame
java.lang.UnsupportedOperationException: null
at java.util.AbstractList.set(AbstractList.java:132)
at java.util.AbstractList$ListItr.set(AbstractList.java:426)
at java.util.Collections.sort(Collections.java:159)
at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:48)
at com.taobao.arthas.core.util.Decompiler.decompile(Decompiler.java:60)
at com.taobao.arthas.core.command.klass100.JadCommand.processExactMatch(JadCommand.java:156)
at com.taobao.arthas.core.command.klass100.JadCommand.process(JadCommand.java:113)
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:370)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

lzc-alioo pushed a commit to lzc-alioo/arthas that referenced this issue May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants