title: Bean Validation API / Hibernate Validator: any way to detect the requested validation groups during validation?
body: <p>Indeed, this is somewhat a duplicate of <a href="https://stackoverflow.com/questions/17385256/bean-validation-get-validation-groups">a previous question</a>, however I was wondering whether, after nine years and some new specification versions being published, the situation has changed in any way, or whether at least a non portable way to solve this problem exists (I mean: does Hibernate Validator allow to do this, even if the API does not?).</p>
  <p>The question is: is there a way I can make my custom constraint validator detect the validation groups that were passed to the validator instance causing the validation to occur, by inspecting the <code>ConstraintValidatorContext</code>?</p>
  <p>Example, suppose I have my bean:</p>
  <pre class="lang-java prettyprint-override"><code>public class MyBean {
  
    @MyConstraint(value = 5, groups = V1.class)
    @MyConstraint(value = 10, groups = {V2.class, V3.class})
    private int foo;
  
    // cut
  }
  </code></pre>
  <p>and a validator call:</p>
  <pre class="lang-java prettyprint-override"><code>validator.validateValue(MyBean.class, &quot;foo&quot;, 7, V2.class);
  </code></pre>
  <p>can my constraint validator detect that <code>V2.class</code> validation group was requested, in this specific case?</p>
  <pre class="lang-java prettyprint-override"><code>public class MyConstraintValidator implements ConstraintValidator&lt;MyConstraint, Integer&gt; {
  
    // cut
  
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
      Class&lt;?&gt;[] requestedValidationGroups = // expected {V2.class} here, in case of the above call
    }
  }
  </code></pre>
  <p>In the <code>initialize</code> method I can get an information about the static declaration of the constraint annotation, so in the above example I could get <code>{V1.class}</code> or <code>{V2.class, V3.class}</code> depending on which of the two constraints the implementation detects as the one being applied. However, I would need to get just <code>{V2.class}</code> in this case.</p>
  <p>Is it possible in some way?</p>
  <p>Looking at Hibernate Validator 6.0 sources, I see I would need access to <code>org.hibernate.validator.internal.engine.ValueContext&lt;T, V&gt;</code>, in particular its <code>currentGroup</code> property, but neither this group nor the <code>ValueContext</code> itself is passed to the Hibernate Validator constraint validator context implementation implementation  (<code>org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorContextImpl</code>), whose creation, on the other hand, seems not to be customisable (there's a direct <code>new ConstraintValidatorContextImpl(...)</code> call in <code>org.hibernate.validator.internal.engine.constraintvalidation.SimpleConstraintTree.validateConstraints(ValidationContext&lt;T&gt;, ValueContext&lt;?, ?&gt;, Set&lt;ConstraintViolation&lt;T&gt;&gt;)</code>).</p>
  <p>Any further hint?</p>