-2

Question 1: How would I change the signatures of entries within the ConstPool? For example, lets say I had a methodref to a method with a signature "()Ljava.util.Collection;". How can I change that to say, "()I"?

I want to do this because when a release comes out for an API, and a dependency on the updated API still uses the old method, I want to change the signature used, making sure that the dependent application implements this safely.

Question 2: How can I iterate through the LongVector of constant pool entries, without having to use reflection every single step of the way? Since LongVector is package private, ConstInfo is package private, and I would have to use reflection to get all the method return types, in a loop too.

This will be used in tandem with problem number 1 to iterate through the constant pool and modify the signatures and store their information in a class lookup.

Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
  • 1
    The two questions seem unrelated. Please split them into two questions. –  Jul 30 '14 at 07:10
  • Should I elaborate more on how I will use them *together*? –  Jul 30 '14 at 07:11
  • Especially show us some code and describe what you expect it to do, what it does, and any error you get. –  Jul 30 '14 at 07:16
  • 1
    You really really really don't want to do this, and I doubt that the Java bytecode verifier will let you. Evolve your API in a backwards-compatible way like everybody else (!) does. – user207421 Jul 30 '14 at 07:25
  • @EJP Honestly, I think it's really creepy how you follow every question of mine, but okay. A bytecode verifier cannot predict runtime conditions, therefore, I don't believe this will happen. Besides that, I renamed a few of my classes that moved out of experimental to production ready, and I have already thought about that... –  Jul 30 '14 at 07:32
  • 1
    Soundw like the worst idea of the day, but still somehow interesting if you could do that :D – Thomas Uhrig Jul 30 '14 at 09:13
  • @ThomasUhrig I *can* do it :P –  Jul 30 '14 at 16:02

1 Answers1

1

1) Use reflection - there's no other way to access the ConstInfo. The signatures can be found in the name and type index of the MethodRef.

2) Use reflection - there's also no other way to access the elements of the LongVector. Get the LongVector, get the elements at each index per size (both which can be accessed using reflection - LongVector simply had to also be package-local), and pass them to question 1.

Thanks for all the help!