This repository was archived by the owner on Jul 6, 2026. It is now read-only.
Commit dbb9edd
authored
[Java.Interop.Tools.JavaTypeSystem] Prefer !synthetic base methods (#1110)
Context: dotnet/android-libraries#723
Imagine we have [the following Java][0]:
public abstract class Key {
public abstract Parameters getParameters();
}
public abstract class StreamingAeadKey extends Key {
@OverRide
public abstract StreamingAeadParameters getParameters();
}
public final class AesGcmHkdfStreamingKey extends StreamingAeadKey {
@OverRide
public AesGcmHkdfStreamingParameters getParameters() { ... }
}
The reabstraction in `StreamingAeadKey.getParameters()` causes an
additional synthetic `getParameters()` method to be generated:
<class name="StreamingAeadKey" abstract="true" deprecated="not deprecated"
jni-extends="Lcom/google/crypto/tink/Key;" extends="com.google.crypto.tink.Key" extends-generic-aware="com.google.crypto.tink.Key" final="false"
jni-signature="Lcom/google/crypto/tink/streamingaead/StreamingAeadKey;"
source-file-name="StreamingAeadKey.java" static="false" visibility="public">
<method abstract="false" name="getParameters" deprecated="not deprecated"
jni-signature="()Lcom/google/crypto/tink/Parameters;"
final="false" native="false" bridge="true" synthetic="true"
return="com.google.crypto.tink.Parameters" jni-return="Lcom/google/crypto/tink/Parameters;"
static="false" synchronized="false" visibility="public"
/>
<method abstract="true" name="getParameters" deprecated="not deprecated"
jni-signature="()Lcom/google/crypto/tink/streamingaead/StreamingAeadParameters;"
final="false" native="false" bridge="false" synthetic="false"
return="com.google.crypto.tink.streamingaead.StreamingAeadParameters" jni-return="Lcom/google/crypto/tink/streamingaead/StreamingAeadParameters;"
static="false" synchronized="false" visibility="public"
/>
</class>
Rephrasing in Java, we have:
/* partial */ class StreamingAeadKey extends Key {
// abstract=false, bridge=true, synthetic=true
public Parameters getParameters() {…}
// abstract=true, bridge=false, synthetic=false
public abstract StreamingAeadParameters getParameters();
}
When looking for the "base method" for
`AesGcmHkdfStreamingKey.getParameters()` we grab the "first" one we
find with a matching name and parameters. In this case, it is the
synthetic method instead of the "regular" method.
Note that the synthetic method is not `abstract`. When deciding if
we need to output `AesGcmHkdfStreamingKey.getParameters()`, we see
that both it and the "base method" are not `abstract`, so we don't
need to bother outputting the derived method.
In reality, the base method should be the `abstract` method. Then it
is different from the derived non-abstract method, and we will output
the derived method to `api.xml.adjusted`.
The fix is to prefer non-`synthetic`, non-`bridge` methods when
choosing base methods.
[0]: https://github.com/google/tink/blob/9bc2667963e20eb42611b7581e570f0dddf65a2b/java_src/src/main/java/com/google/crypto/tink/Key.java1 parent 3038d60 commit dbb9edd
2 files changed
Lines changed: 63 additions & 1 deletion
File tree
- src/Java.Interop.Tools.JavaTypeSystem/JavaModels
- tests/Java.Interop.Tools.JavaTypeSystem-Tests
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
81 | 89 | | |
82 | 90 | | |
83 | 91 | | |
| |||
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
86 | 140 | | |
87 | 141 | | |
0 commit comments