Skip to content

Extend Reflector.loadClass to accept primitive type names#14

Merged
Howard20181 merged 3 commits intodocsfrom
copilot/sub-pr-2
Feb 10, 2026
Merged

Extend Reflector.loadClass to accept primitive type names#14
Howard20181 merged 3 commits intodocsfrom
copilot/sub-pr-2

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

encodeClass() uses Class.getName() which returns "int" for primitives, but Reflector.loadClass() only accepted descriptors like "I", breaking cache round-tripping for primitive types.

Changes

  • Added primitive name lookup in loadClass() using existing abbreviationMap (maps "int"'I'int.class)
  • Added clarifying comment about map structure
  • Preserves backward compatibility with descriptors ("I"), object types ("java.lang.String"), and arrays ("int[]")
// Before: loadClass("I") ✓    loadClass("int") ✗
// After:  loadClass("I") ✓    loadClass("int") ✓

Class<?> loadClass(String className) {
    // ... existing descriptor handling ...
    
    // Handle primitive type names (e.g., "int", "boolean", "void")
    Character primitiveDescriptor = abbreviationMap.get(className);
    if (primitiveDescriptor != null) {
        return primitiveClassMap.get(primitiveDescriptor);
    }
    
    // ... rest of class loading logic ...
}

💡 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.

Copilot AI and others added 2 commits February 10, 2026 14:43
Co-authored-by: Howard20181 <40033067+Howard20181@users.noreply.github.com>
…ionMap usage

Co-authored-by: Howard20181 <40033067+Howard20181@users.noreply.github.com>
Copilot AI changed the title [WIP] Update implementation of primitive names in Reflector.loadClass Extend Reflector.loadClass to accept primitive type names Feb 10, 2026
Copilot AI requested a review from Howard20181 February 10, 2026 14:47
@Howard20181 Howard20181 marked this pull request as ready for review February 10, 2026 14:53
Copilot AI review requested due to automatic review settings February 10, 2026 14:53
@Howard20181 Howard20181 merged commit aec7c9b into docs Feb 10, 2026
@Howard20181 Howard20181 deleted the copilot/sub-pr-2 branch February 10, 2026 14:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 existing abbreviationMap to 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants