question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the reason for checking the amount of annotations on the classes

See original GitHub issue

https://github.com/cucumber/cucumber-jvm/blob/master/spring/src/main/java/cucumber/runtime/java/spring/SpringFactory.java

private void checkAnnotationsEqual(Class<?> stepClassWithSpringContext, Class<?> stepClass) {
        Annotation[] annotations1 = stepClassWithSpringContext.getAnnotations();
        Annotation[] annotations2 = stepClass.getAnnotations();
        if (annotations1.length != annotations2.length) {
            throw new CucumberException("Annotations differs on glue classes found: " +
                    stepClassWithSpringContext.getName() + ", " +
                    stepClass.getName());
        }
        for (Annotation annotation : annotations1) {
            if (!isAnnotationInArray(annotation, annotations2)) {
                throw new CucumberException("Annotations differs on glue classes found: " +
                        stepClassWithSpringContext.getName() + ", " +
                        stepClass.getName());
            }
        }
    }

What is the technical reason for this?

This check has broken again the compatibility…

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
brasmussoncommented, Nov 14, 2014

To make the spring transactions (#637) and auto-wiring of one stepdef class to another (which you know of https://github.com/cucumber/cucumber-jvm/issues/569#issuecomment-26699067), the SpringFactory will create bean definitions for all the glue classes in the context defined by one (the first one found) glue class with a @ContextConfiguration/@ContextHierachy annotation. As SpringFactory (after #711) works, this one class is the only class that Spring will be aware of and therefor its annotations are applied globally (so to say). This guard is there to prevent the any problems caused by silently not using the annotations the user thinks will be used, it is essentially saying “this won’t work as you think, so let’s not continue”.

Is it possible to allow different context definitions on different glue classes? Maybe, but it seems very complex. Is it possible to allow different annotations, but the same context definition, on different glue classes? Maybe not as complex as allowing different contexts, but still complex. At least it looks like this to me.

Links to some discussions about this: https://github.com/cucumber/cucumber-jvm/pull/711#discussion_r12776747 on the mailing list

0reactions
lock[bot]commented, Feb 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Annotations in Java - GeeksforGeeks
Annotations help to associate metadata (information) to the program elements i.e. instance variables, constructors, methods, classes, etc.
Read more >
Detecting the present annotations within the given object ...
First you need to have retention policy on your annotations so you can read them with reflection @Retention(RetentionPolicy.
Read more >
An Introduction to Annotations and Annotation Processing in ...
Annotations provide information to a program at compile time or at runtime based on which the program can take further action.
Read more >
Annotating a Text - Reading and Study Strategies
Annotating means you are doing the hard work while you read, allowing you to reference your previous work and have a clear jumping-off...
Read more >
Java Annotations - Jenkov.com
A Java annotation is a small comment-like construct you can insert before class, method and field declarations. Annotations can be used to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found