0

Hot code replace works for me on instance methods, but not on static methods. I get this error enter image description here

Note that I am simply adding a println to the body of a static private or even public method, not changing any method modifiers, as suggested by the error message. How do I achieve this hot replacement?

I am using Eclipse Oxygen and Java 8 JRE. Maven com.google.cloud.tool:appengine-maven-plugin is used to launch app in debug mode with goal
appengine:run. I then connect with the Eclipse remote debugger.

Joshua Fox
  • 18,704
  • 23
  • 87
  • 147
  • A `static private` method can be optimized, e. g. by inlining where it is called. Does the method exist in the bytecode? If not, _Hot Code Replace_ cannot find the method to replace. – howlger Jul 29 '18 at 12:45
  • Good point But this behavior occurs for all static methods, including public – Joshua Fox Jul 29 '18 at 13:26

1 Answers1

1

On Hot Code Replace, the whole class file is replaced. To find out the exact reason why the files cannot be exchanged, you would have to compare the original bytecode with the one to be changed.

By default, Maven uses javac for compiling, whereas the file to be swapped is compiled with Eclipse's own Java compiler. Different optimizations can lead to the classes file not being swappable, especially if private methods, fields or constants are used.

One of the following might solve your issue:

howlger
  • 31,050
  • 11
  • 59
  • 99
  • 1
    Using the Eclipse compiler in the Maven build did it for me! Specifically, adding eclipse org.codehaus.plexus plexus-compiler-eclipse 2.8.1 – Joshua Fox Jul 30 '18 at 12:29
  • The key is to have the same compiler -- we were using an external JDK to compile, which differed from Eclipse's internal compiler. – Joshua Fox Jul 31 '18 at 11:14