Status Update
Comments
lb...@gmail.com <lb...@gmail.com>
mm...@google.com <mm...@google.com>
er...@google.com <er...@google.com>
tn...@google.com <tn...@google.com>
tn...@google.com <tn...@google.com> #2
I can reproduce this (thanks for the repro project!)
It looks like the problem is that the desugared api list from r8 contains this entry:
java/util/Collection#removeIf(Ljava/util/function/Predicate;)Z
but the bytecode here doesn't match -- it's java/util/ArrayList. Collection isn't a directly implemented interface or a direct super class, it's an interface on the super super class. The most efficient thing runtime wise would be for the signature list to inline this method on all implemented subclasses. But I should probably at least for now go and make the desugared API lookup do something similar to what it does for API lookup -- search through all super classes and interfaces as well. This isn't a new problem, so I'm very surprised this hasn't come up before (or it has, and I've forgotten).
lb...@gmail.com <lb...@gmail.com> #3
(I have a pending CL that was working to improve the handling of fields now that r8 handles desugaring fields, I'll try to dust that off and combine the fix in there.)
sa...@google.com <sa...@google.com> #4
I went to implement this, and hooked up inheritance search when analyzing the source file containing the call.
However, lint also handles the case where the library being analyzed is not using core library desugaring (for example, it may be a plain Java library). But when that library is consumed in a downstream app module, where library desugaring is turned on, lint then processes the partial results from the library and filters each violation through the desugaring allowlist.
At this point, it's tricky to do the inheritance search -- this happens when we no longer have a compilation environment and can do class inheritance lookups. So there are three possible solutions.
First, we pay the cost up front -- even when you're not using core library desugaring, we record whether the method is potentially library desugared if turned on. (This is also tricky because at this point we don't know which exact desugaring library version is used, which determines the exact list of APIs).
Or, more expensively, for every API violation of this type we store all the potential super class and interface names for each result...
Or, we handle this in the code which generates the desugaring API list, inlining all subclasses affected. This could be quite a long list, but on the other hand this list is really only intended to be machine readable.
lb...@gmail.com <lb...@gmail.com> #5
This is partially fixed now; it's fully fixed for the sample project, but in the scenario I described in comment 4, it works if you also configure library desugaring to be on in the library.
Description
STEPS TO REPRODUCE:
1. Have this code, which clearly checks for version code to use the function that has no second parameter from Android P:
final Cipher cipher = VERSION.SDK_INT >= VERSION_CODES.P ?
Cipher.getInstance("RSA/NONE/OAEPWithSHA256AndMGF1Padding") :
Cipher.getInstance("RSA/NONE/OAEPWithSHA256AndMGF1Padding", "BC");
or this in Kotlin:
val cipher: Cipher =
if (VERSION.SDK_INT >= VERSION_CODES.P) Cipher.getInstance("RSA/NONE/OAEPWithSHA256AndMGF1Padding")
else Cipher.getInstance("RSA/NONE/OAEPWithSHA256AndMGF1Padding", "BC")
2. Perform code analysis
The bug is that it shows a warning that you shouldn't use the one with "BC", as it will throw an exception on Android P, even though there is no way such a thing will occur:
"
The 'BC' provider is deprecated and as of Android P this method will throw a 'NoSuchAlgorithmException'. To fix this you should stop specifying a provider and use the default implementation
"
------------------
Studio Build:
Version of Gradle Plugin:
Version of Gradle:
Version of Java:
OS:
Android Studio Flamingo | 2022.2.1 Canary 9
Build #AI-222.4345.14.2221.9321504, built on November 23, 2022
Runtime version: 17.0.4.1+0-b2043.56-9127311 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 9048M
Cores: 12
Registry:
external.system.auto.import.disabled=true
debugger.watches.in.variables=false
ide.text.editor.with.preview.show.floating.toolbar=false
gradle.version.catalogs.dynamic.support=true
ide.images.show.chessboard=true
Non-Bundled Plugins:
idea.plugin.protoeditor (222.4345.14)
com.intellij.marketplace (222.4345.34)
com.dubreuia (2.3.0)
com.dethlex.numberconverter (1.5.0)
String Manipulation (9.6.1)
Show As ... (1.0.3)
GenerateSerializationHelpers (1.0.6)
GenerateSerialVersionUID (3.0.3)
com.google.mad-scorecard (1.2)
com.developerphil.adbidea (1.6.8)
net.aquadc.mike.plugin (0.27)
izhangzhihao.rainbow.brackets (2022.3.5-ij)
com.ppismerov.ksvu (0.0.1)