Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in Groovy: ClassCastException for closures not returning Boolean #71

Closed
pkubowicz opened this issue Jan 17, 2017 · 12 comments
Closed

Comments

@pkubowicz
Copy link
Contributor

Code:

Awaitility.await().until({ "something" })

1.7.0: passes
2.0.0: fails with

java.lang.String cannot be cast to java.lang.Boolean
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
	at org.awaitility.core.CallableCondition$ConditionEvaluationWrapper.eval(CallableCondition.java:100)
	at org.awaitility.core.ConditionAwaiter$ConditionPoller.run(ConditionAwaiter.java:215)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

AwaitilityGroovyBridge used runnable as Callable<Boolean> while AwaitilityExtensionModule uses runnable as Callable.

Implementing AwaitilityTrait does not help, it seems that the extension module takes precedence. You need to change the closure to { "something" != null }.

Release Notes don't mention any breaking changes, so I consider this as a regression.

Also, please update examples from https://github.com/awaitility/awaitility/wiki/Groovy - they use deprecated classes.

@johanhaleby
Copy link
Collaborator

Thanks for pointing this out, I didn't know this. Is there a way to work-around this in the code to make it work again that you're aware of?

@pkubowicz
Copy link
Contributor Author

I tried writing my own extension module, but I gave up, as a special entry in the JAR manifest is needed.

@johanhaleby
Copy link
Collaborator

Ok, so the org.codehaus.groovy.runtime.ExtensionModule file in /META-INF/services is not enough?

@pkubowicz
Copy link
Contributor Author

It is probably enough, but I would need to create a JAR with my new extensions and add a dependency on it to tests. In my case it was faster to change the code.

@johanhaleby
Copy link
Collaborator

I've published a new snapshot that I would be glad if you could try out to see if it works: 2.0.1-SNAPSHOT.

You'll need the following maven repo:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>

@pkubowicz
Copy link
Contributor Author

This does not work, but I have a fix in my fork, I'll submit a merge request soon.

@szpak
Copy link
Contributor

szpak commented Jan 17, 2017

Related to #65.

Btw, @pkubowicz it is not required to build and add as a dependency a JAR to create a new extension. Putting a proper file in META-INF/services in src/test/resources should be enough.

pkubowicz added a commit to pkubowicz/awaitility that referenced this issue Jan 17, 2017
@pkubowicz
Copy link
Contributor Author

I submitted my changes in #72

@johanhaleby
Copy link
Collaborator

Thanks! Can I close this issue? (perhaps you could add the wiki updates as a new issue)

@johanhaleby
Copy link
Collaborator

I've also published a new snapshot

pkubowicz added a commit to pkubowicz/awaitility that referenced this issue Jan 18, 2017
… AwaitilitySupport

AwaitilityGroovyBridge needs to be removed because depending on random factors
(class loading?) it can overwrite code added by AwaitilityExtensionModule and
cause non-bool closures to fail - this is reproduced by tests added in this commit.

AwaitilityTrait and AwaitilitySupport can be made empty as AwaitilityExtensionModule
does their work now. They are left only to prevent a breaking API change.
@pkubowicz
Copy link
Contributor Author

I found some problems if you had AwaitilityTrait in your code. My fixes in #73.

@pkubowicz
Copy link
Contributor Author

I don't see any problems with the current snapshot - I am closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants