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

Groovy extension is activated even though vertx-lang-groovy is not in the classpath #44

Closed
cazacugmihai opened this issue Apr 11, 2017 · 7 comments

Comments

@cazacugmihai
Copy link

cazacugmihai commented Apr 11, 2017

Version

  • vert.x core: 3.4.1, 3.4.2-SNAPSHOT
  • vert.x sql common: 3.4.1, 3.4.2-SNAPSHOT
  • groovy: 2.4.10, 2.5.0-SNAPSHOT

Context

I've got this exception:

java.lang.ClassCastException: io.vertx.core.json.JsonArray cannot be cast to java.util.List
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_121]
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) ~[?:1.8.0_121]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[?:1.8.0_121]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[?:1.8.0_121]
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[?:1.8.0_121]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_121]
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[?:1.8.0_121]
	at io.vertx.groovy.ext.sql.SQLConnection_GroovyExtension.batchWithParams(SQLConnection_GroovyExtension.java:73) ~[vertx-sql-common-3.4.2-SNAPSHOT.jar:?]

and, because the groovy-all jar is present in the classpath, the groovy extension is loaded.

Is it possible to not use the Groovy extrension as long as I don't use vertx-lang-groovy?

Extra

It may be related to this issue. If true, please check every other module for this kind of situation.

@cazacugmihai
Copy link
Author

Is there a way to fix the mentioned error?

When the code is compiled, this method is used:

SQLConnection.batchWithParams(String sqlStatement, List<JsonArray> args, Handler<AsyncResult<List<Integer>>> handler)

but, at runtime, this one is called:

SQLConnection_GroovyExtension.batchWithParams(SQLConnection j_receiver, String sqlStatement, List<List<Object>> args, Handler<AsyncResult<List<Integer>>> handler)

and the code fails on this line (from the above method):

io.vertx.core.impl.ConversionHelper.toJsonArray(elt)

because there is a JsonArray in the args param and ConversionHelper.toJsonArray accepts a List<Object> param.

@cazacugmihai
Copy link
Author

cazacugmihai commented Apr 12, 2017

The reproducer:

// @GrabResolver(name='mavenLocal', root='file:/home/mcazacu/.m2/repository/')
// @GrabResolver(name='restlet', root='https://oss.sonatype.org/content/repositories/snapshots/')
// @Grapes([
// 	@Grab("io.vertx:vertx-core:3.4.2-SNAPSHOT"),
// 	@Grab("io.vertx:vertx-jdbc-client:3.4.2-SNAPSHOT"),
// 	@Grab("com.h2database:h2:1.4.194")
// ])

@Grapes([
	@Grab("io.vertx:vertx-core:3.4.1"),
	@Grab("io.vertx:vertx-jdbc-client:3.4.1"),
	@Grab("com.h2database:h2:1.4.194")
])
import groovy.transform.CompileStatic
import io.vertx.core.AsyncResult
import io.vertx.core.Handler
import io.vertx.core.Future
import io.vertx.core.Vertx
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject
import io.vertx.ext.jdbc.JDBCClient
import io.vertx.ext.sql.SQLConnection

import static io.vertx.core.Future.future

//@CompileStatic
void reproduce() {
	Vertx vertx = Vertx.vertx()
	JDBCClient client = JDBCClient.createNonShared(
		vertx,
		new JsonObject([
			url        : 'jdbc:h2:mem:people?shutdown=true',
			driverclass: 'org.h2.Driver'
		] as Map<String, Object>)
	)

	println 'Step #1: Obtaining connection...'
	client.getConnection { AsyncResult<SQLConnection> arConn ->
		println 'Step #1: Obtaining connection...' + arConn.succeeded()
		SQLConnection conn = arConn.result()

		println 'Step #2: Removing table...'
		conn.execute('drop table if exists person') { AsyncResult<Void> arDrop ->
			println 'Step #2: Removing table...' + arDrop.succeeded()

			println 'Step #3: Creating table...'
			conn.execute('create table person (name varchar(100))') { AsyncResult<Void> arCreate ->
				println 'Step #3: Creating table...' + arCreate.succeeded()

				println 'Step #4: Inserting data...'

				String sql = 'insert into person (name) values (?)'
				List<JsonArray> args = ['Jane', 'John'].collect { new JsonArray([it]) }

				Future<List<Integer>> f = future()
				
				conn.batchWithParams(sql, args, f.completer())

				f.setHandler({ AsyncResult<List<Integer>> arInsert ->
					println 'Step #4: Inserting data...' + arInsert.succeeded()
					
					println arInsert.result()
				} as Handler <AsyncResult<List<Integer>>>)
			}
		}
	}
}

reproduce()

@cazacugmihai
Copy link
Author

Console:

Step #1: Obtaining connection...true
Step #2: Removing table...
Step #2: Removing table...true
Step #3: Creating table...
Step #3: Creating table...true
Step #4: Inserting data...
Apr 12, 2017 1:37:46 PM io.vertx.core.impl.ContextImpl
SEVERE: Unhandled exception
java.lang.ClassCastException: io.vertx.core.json.JsonArray cannot be cast to java.util.List
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at io.vertx.groovy.ext.sql.SQLConnection_GroovyExtension.batchWithParams(SQLConnection_GroovyExtension.java:73)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:54)
	at org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:56)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)
	at test$_reproduce_closure1$_closure2$_closure3.doCall(test.groovy:49)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1027)
	at groovy.lang.Closure.call(Closure.java:414)
	at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:54)
	at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:124)
	at com.sun.proxy.$Proxy8.handle(Unknown Source)
	at io.vertx.core.impl.FutureImpl.checkCallHandler(FutureImpl.java:188)
	at io.vertx.core.impl.FutureImpl.setHandler(FutureImpl.java:100)
	at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:287)
	at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:337)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:445)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	at java.lang.Thread.run(Thread.java:745)

@cazacugmihai
Copy link
Author

It seems that the error was thrown when using groovy 2.5.0-SNAPSHOT. With 2.4.10 everything is fine. Thanks @vietj for your help!

@cazacugmihai
Copy link
Author

I was wrong. I don't know why it was working a few hours ago. The error is still reproduced using also groovy 2.4.10.

@cazacugmihai cazacugmihai reopened this Apr 12, 2017
@cazacugmihai
Copy link
Author

Can someone (from DEV team) confirm that is able to reproduce the issue, please? Should I give more info, maybe? If so, what else do you need?

Thanks!

@pmlopes
Copy link
Member

pmlopes commented Apr 13, 2017

Issue moved to vert-x3/vertx-lang-groovy #48 via ZenHub

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

No branches or pull requests

2 participants