RFR: StateObjectHandler.validateState(): fix typo and optimize [v2]

wangpeipei90 github.com+4886855+wangpeipei90 at openjdk.java.net
Mon Oct 26 15:25:19 UTC 2020


On Mon, 26 Oct 2020 15:06:18 GMT, Sergey Ponomarev <github.com+415502+stokito at openjdk.org> wrote:

>> jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java line 107:
>> 
>>> 105:         boolean hasDefaultConstructor = false;
>>> 106:         for (MethodInfo constructor : state.getConstructors()) {
>>> 107:             if (constructor.getParameters().isEmpty()) {
>> 
>> The changes here are not equivalent.  If any constructor`isEmpty `and `isPublic`, `hasDefaultConstructor` will always be `True`. 
>> 
>> But in the code change, the early exit could cause `hasDefaultConstructor` be `false` if there is a constructor `isEmpty` but not `isPublic` without iterating the default constructor yet.
>
> is it possible to have two default constructors with empty params? Maybe not in Java but in some alternative language?
> As far I know this is prohibited.
> If we can have only one empty param constructor then we can check only it for having a public modifier and then skip others

I was thinking of the case the default constructor is declared explicitly with the `private` modifier. But you are right that a Java class could not have two default constructors with empty params, according to the rule of the method signature. The change is not equivalent, it still fulfills the same purpose.

-------------

PR: https://git.openjdk.java.net/jmh/pull/7


More information about the jmh-dev mailing list