Extend Reflector.loadClass to accept primitive type names#14
Extend Reflector.loadClass to accept primitive type names#14Howard20181 merged 3 commits intodocsfrom
Conversation
Co-authored-by: Howard20181 <40033067+Howard20181@users.noreply.github.com>
…ionMap usage Co-authored-by: Howard20181 <40033067+Howard20181@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a cache round-tripping bug for primitive types by extending Reflector.loadClass() to accept primitive type names (e.g., "int", "boolean") in addition to their single-letter descriptors (e.g., "I", "Z"). The issue occurred because encodeClass() uses Class.getName() which returns names like "int" for primitives, but loadClass() only accepted descriptors like "I".
Changes:
- Added primitive name lookup in
Reflector.loadClass()using the existingabbreviationMapto map names to descriptors - Added clarifying comment explaining the map's purpose
Comments suppressed due to low confidence (15)
helper/src/main/java/io/github/libxposed/helper/Reflector.java:24
- Type 'Method' does not define hashCode(), but is used in a hashing data-structure.
private final HashMap<MemberKey.Method, WeakReference<Method>> methodCache = new HashMap<>();
helper/src/main/java/io/github/libxposed/helper/Reflector.java:25
- Type 'Field' does not define hashCode(), but is used in a hashing data-structure.
private final HashMap<MemberKey.Field, WeakReference<Field>> fieldCache = new HashMap<>();
helper/src/main/java/io/github/libxposed/helper/Reflector.java:26
- Type 'Constructor' does not define hashCode(), but is used in a hashing data-structure.
private final HashMap<MemberKey.Constructor, WeakReference<Constructor<?>>> constructorCache = new HashMap<>();
helper/src/main/java/io/github/libxposed/helper/Reflector.java:142
- Type 'Field' does not define hashCode(), but is used in a hashing data-structure.
ref = fieldCache.get(key);
helper/src/main/java/io/github/libxposed/helper/Reflector.java:157
- Type 'Field' does not define hashCode(), but is used in a hashing data-structure.
fieldCache.put(key, (WeakReference<Field>) EMPTY);
helper/src/main/java/io/github/libxposed/helper/Reflector.java:163
- Type 'Field' does not define hashCode(), but is used in a hashing data-structure.
fieldCache.put(key, new WeakReference<>(field));
helper/src/main/java/io/github/libxposed/helper/Reflector.java:273
- Type 'Method' does not define hashCode(), but is used in a hashing data-structure.
ref = methodCache.get(key);
helper/src/main/java/io/github/libxposed/helper/Reflector.java:288
- Type 'Method' does not define hashCode(), but is used in a hashing data-structure.
methodCache.put(key, (WeakReference<Method>) EMPTY);
helper/src/main/java/io/github/libxposed/helper/Reflector.java:294
- Type 'Method' does not define hashCode(), but is used in a hashing data-structure.
methodCache.put(key, new WeakReference<>(method));
helper/src/main/java/io/github/libxposed/helper/Reflector.java:386
- Type 'Constructor' does not define hashCode(), but is used in a hashing data-structure.
ref = constructorCache.get(key);
helper/src/main/java/io/github/libxposed/helper/Reflector.java:398
- Type 'Constructor' does not define hashCode(), but is used in a hashing data-structure.
constructorCache.put(key, (WeakReference<Constructor<?>>) EMPTY);
helper/src/main/java/io/github/libxposed/helper/Reflector.java:404
- Type 'Constructor' does not define hashCode(), but is used in a hashing data-structure.
constructorCache.put(key, new WeakReference<>(constructor));
helper/src/main/java/io/github/libxposed/helper/Reflector.java:496
- Class Constructor overrides equals but not hashCode.
static class Constructor extends MemberKey {
helper/src/main/java/io/github/libxposed/helper/Reflector.java:523
- Class Method overrides equals but not hashCode.
static class Method extends MemberKey {
helper/src/main/java/io/github/libxposed/helper/Reflector.java:469
- Class Field overrides equals but not hashCode.
static class Field extends MemberKey {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
encodeClass()usesClass.getName()which returns"int"for primitives, butReflector.loadClass()only accepted descriptors like"I", breaking cache round-tripping for primitive types.Changes
loadClass()using existingabbreviationMap(maps"int"→'I'→int.class)"I"), object types ("java.lang.String"), and arrays ("int[]")💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.