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

java.lang.ClassCastException when searching for field usage #1489

Closed
j4k0xb opened this issue May 21, 2022 · 7 comments
Closed

java.lang.ClassCastException when searching for field usage #1489

j4k0xb opened this issue May 21, 2022 · 7 comments
Labels
bug GUI Issues in jadx-gui module regression
Milestone

Comments

@j4k0xb
Copy link

j4k0xb commented May 21, 2022

Reproduction steps:

  1. Open the apk from here
  2. Go to the public int A; field in the e.a.b.d0 class
  3. Find Usage

Info:

  • Jadx version: 1.4.0
  • Java version: 11.0.15
  • Java VM: Oracle Corporation OpenJDK 64-Bit Server VM
  • Platform: Linux (5.15.32-1-MANJARO amd64)
  • Max heap size: 11116 MB
  • Program args: -Xms128M -XX:MaxRAMPercentage=70.0 -XX:+UseG1GC -Dawt.useSystemAAFontSettings=lcd -Dswing.aatext=true

Stacktrace:

java.lang.ClassCastException: class jadx.api.JavaClass cannot be cast to class jadx.api.JavaVariable (jadx.api.JavaClass and jadx.api.JavaVariable are in unnamed module of loader 'app')
	at jadx.api.JadxDecompiler.resolveVarRef(JadxDecompiler.java:689)
	at jadx.api.JadxDecompiler.getJavaNodeByCodeAnnotation(JadxDecompiler.java:661)
	at jadx.api.JavaClass.getUsePlacesFor(JavaClass.java:203)
	at jadx.gui.ui.dialog.UsageDialog.processUsage(UsageDialog.java:101)
	at jadx.gui.ui.dialog.UsageDialog.lambda$null$1(UsageDialog.java:69)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.DistinctOps$1$2.accept(DistinctOps.java:175)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
	at jadx.gui.ui.dialog.UsageDialog.lambda$collectUsageData$2(UsageDialog.java:69)
	at java.base/java.util.HashMap.forEach(HashMap.java:1337)
	at jadx.gui.ui.dialog.UsageDialog.collectUsageData(UsageDialog.java:66)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

@j4k0xb j4k0xb changed the title java.lang.ClassCastException: class jadx.api.JavaClass cannot be cast to class jadx.api.JavaVariable (jadx.api.JavaClass and jadx.api.JavaVariable are in unnamed module of loader 'app') java.lang.ClassCastException when searching for field usage May 21, 2022
@skylot
Copy link
Owner

skylot commented May 21, 2022

@j4k0xb thanks!
I commit a fix. It is actually a workaround because I still not resolve all causes, but at least this will not throw class cast exception.

@skylot skylot added bug GUI Issues in jadx-gui module regression labels May 21, 2022
@skylot skylot added this to the TBD milestone May 21, 2022
@skylot
Copy link
Owner

skylot commented May 23, 2022

I think I fixed the root cause of the issue: disk cache uses too small number type (short) to store code offsets, so sometimes value overflows. I update that format to variable length encoding: ULEB128 (also used in dex) to use less disk space because most classes are not very big.

@j4k0xb you can check the latest unstable build, let me know if you find any new issues 🙂

@skylot skylot closed this as completed May 23, 2022
@j4k0xb
Copy link
Author

j4k0xb commented May 23, 2022

couldnt find any other issue 🙂

@j4k0xb
Copy link
Author

j4k0xb commented May 24, 2022

@skylot
nvm I encountered another error (jadx built at commit 5099e02).
Could also be related to disk cache, or because it's a split apk?

Reproduction steps:

  1. Open base.zip (rename to .apk)
  2. Go to com.moshbit.studo.home.HomePagerAdapter
  3. Click on it's class name and find usage

Stacktrace:

jadx.core.utils.exceptions.JadxRuntimeException: JavaMethod not found by MethodNode: kotlin.collections.MapsKt.mapOf(kotlin.Pair):java.util.Map
	at jadx.api.JadxDecompiler.getJavaMethodByNode(JadxDecompiler.java:556)
	at jadx.api.JadxDecompiler.getJavaNodeByCodeAnnotation(JadxDecompiler.java:653)
	at jadx.api.JavaClass.getUsePlacesFor(JavaClass.java:209)
	at jadx.gui.ui.dialog.UsageDialog.processUsage(UsageDialog.java:101)
	at jadx.gui.ui.dialog.UsageDialog.lambda$collectUsageData$1(UsageDialog.java:69)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.DistinctOps$1$2.accept(DistinctOps.java:175)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
	at jadx.gui.ui.dialog.UsageDialog.lambda$collectUsageData$2(UsageDialog.java:69)
	at java.base/java.util.HashMap.forEach(HashMap.java:1337)
	at jadx.gui.ui.dialog.UsageDialog.collectUsageData(UsageDialog.java:66)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

@skylot
Copy link
Owner

skylot commented May 26, 2022

@j4k0xb sadly but I can't reproduce this issue, maybe it is a multithreaded issue.
I will try to add more logging and maybe fix some paths of possible cause.

@skylot
Copy link
Owner

skylot commented May 28, 2022

@j4k0xb I commit another bunch of changes, hope it will fix these issues.

@skylot skylot closed this as completed May 28, 2022
@j4k0xb
Copy link
Author

j4k0xb commented May 28, 2022

but I can't reproduce this issue

Just tried it again with the old version and couldn't reproduce it either.
Find usage works fine so I can't tell if it's fixed, but unless it happens again I think this issue can stay closed 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug GUI Issues in jadx-gui module regression
Projects
None yet
Development

No branches or pull requests

2 participants