After upgrading our source from 60.0
to 61.0
, I observed regression in some of our libraries. After investigation, I noticed that api version 61.0
breaks (changes?) the way, inheritance for inner classes worked.
In 60 and below, you can declare an inner classes with private virtual
methods and override these methods in another inner class (this only works for inner classes in the same apex class for obvious reasons). When instantiating the subclass polymorphic (e.g. assinging to a variable of Superclass, it correctly calls the overwritten method, not theS ubclass. This has changed in 61.
I can consistently reproduce this behaviour with anonymous apex and deployed code. Take this example code and run it with --api-version 60.0
and --api-version 61.0
.
public class Superclass1 {
private virtual String myMethod() {
return 'Superclass1';
}
}
public class Subclass2 extends Superclass1 {
private override String myMethod() {
return 'Subclass2';
}
}
Superclass1 instanceOf1 = new Superclass1();
Superclass1 instanceOf2 = new Subclass2();
System.debug('Class 1: ' + instanceOf1.myMethod());
System.debug('Class 2: ' + instanceOf2.myMethod());
Output for 60.0 (redacted for readability)
60.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO
05:26:06.34 (34414904)|USER_INFO|[EXTERNAL]|0059K00000BZZ6D|[email protected]|(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)|GMT-07:00
05:26:06.34 (34436723)|EXECUTION_STARTED
05:26:06.34 (34444786)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
05:26:06.34 (35208995)|USER_DEBUG|[16]|DEBUG|Class 1: Superclass1
05:26:06.34 (40878759)|USER_DEBUG|[17]|DEBUG|Class 2: Subclass2
05:26:06.40 (40985945)|CUMULATIVE_LIMIT_USAGE
05:26:06.40 (40985945)|LIMIT_USAGE_FOR_NS|(default)|
[...]
05:26:06.40 (40985945)|CUMULATIVE_LIMIT_USAGE_END
05:26:06.34 (41017930)|CODE_UNIT_FINISHED|execute_anonymous_apex
05:26:06.34 (41031865)|EXECUTION_FINISHED
Same output, run on the same org, but with --api-version 61.0
61.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO
05:26:13.42 (42756298)|USER_INFO|[EXTERNAL]|0059K00000BZZ6D|[email protected]|(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)|GMT-07:00
05:26:13.42 (42787091)|EXECUTION_STARTED
05:26:13.42 (42794748)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
05:26:13.42 (43802330)|USER_DEBUG|[16]|DEBUG|Class 1: Superclass1
05:26:13.42 (43847036)|USER_DEBUG|[17]|DEBUG|Class 2: Superclass1
05:26:13.43 (43959585)|CUMULATIVE_LIMIT_USAGE
05:26:13.43 (43959585)|LIMIT_USAGE_FOR_NS|(default)|
[...]
05:26:13.43 (43959585)|CUMULATIVE_LIMIT_USAGE_END
05:26:13.42 (44019892)|CODE_UNIT_FINISHED|execute_anonymous_apex
05:26:13.42 (44033182)|EXECUTION_FINISHED
More investigation using the Apex Replay Debugger shows, that the code enters the Subclass2 (in v60 and earlier), but enters Subclass1 (in v61).
Is this intended behaviour? Is this a bug?