Projects tigase _server server-core Issues #869
DBSchemaLoader is not replicable for creating admin account (#869)
Daniele Ricci opened 7 years ago

I use Docker with Tigase to build my instance and when I call DBSchemaLoader to initialize/upgrade my schema, I also add -adminJID/-adminJIDpass to automatically create an admin account if it doesn't exist. I know I could extend my Docker scripts to connect to the database preemptively, but it would be good if the DBSchemaLoader would just issue a warning and skip creation of the admin account because it already exists, instead of just throwing an error:

Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
        at com.sun.proxy.$Proxy2.execute(Unknown Source)
        at tigase.db.jdbc.TigaseCustomAuth.addUser(TigaseCustomAuth.java:357)
        at tigase.util.DBSchemaLoader.addXmppAdminAccount(DBSchemaLoader.java:830)
        at tigase.util.DBSchemaLoader$Tasks$4.execute(DBSchemaLoader.java:1049)
        at tigase.util.DBSchemaLoader.execute(DBSchemaLoader.java:215)
        at tigase.util.DBSchemaLoader.main(DBSchemaLoader.java:193)
Caused by: java.lang.reflect.InvocationTargetException
        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 tigase.db.jdbc.PreparedStatementInvocationHandler.invoke(PreparedStatementInvocationHandler.java:37)
        ... 6 more
Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry 'be1cea043b3fffd023083bbf0a928914ed05bb0a' for key 'sha1_user_id'
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:533)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115)
        at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1983)
        at com.mysql.cj.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1826)
        at com.mysql.cj.jdbc.PreparedStatement.execute(PreparedStatement.java:1153)
        at com.mysql.cj.jdbc.CallableStatement.execute(CallableStatement.java:795)
        ... 11 more

Although the exception is somewhat strange... MySQL for Java is indeed in the classpath (otherwise connection wouldn't have worked, besides the stacktrace clearly shows mysql driver packages). Honestly I don't understand what it's complaining about. It can't find the exception class however a few lines later the exception class is in java.sql and it's been present since Java 1.6.

Andrzej Wójcik (Tigase) commented 7 years ago

This log entry never mentioned that it is unable to find an exception class, but it mentions that exception was not declared as being thrown by a method. This issue was introduced by a recent change in database access layer.

Daniele Ricci commented 7 years ago

I've just realized TigaseCustomAuth should throw a UserExistsException if a SQLIntegrityConstraintViolationException occurs. So the problem could actually be inside the mysql driver. I'm using version 6.0.5, "reverting" (the official latest version is prior to that) to 5.1.43 did not fix the issue.

I'll do some more research on the matter.

Daniele Ricci commented 7 years ago

Andrzej Wójcik wrote:

This log entry never mentioned that it is unable to find an exception class, but it mentions that exception was not declared as being thrown by a method. This issue was introduced by a recent change in database access layer.

Oh, I didn't get that (never have seen the exception before). Thanks for your feedback!

Andrzej Wójcik (Tigase) commented 7 years ago

I've found that exceptions thrown with a call to methods using reflection in PreparedStatementInvocationHandler were not properly unwrapped and as a result exceptions unhandled in our code were being thrown. As a result unhandled exceptions were thrown and proper logic of exception handling was not executed.

This issue is fixed in the recent commit to stable and master branch and will be part of the next snapshot build for versions 7.1.1. and @7.2.0@.

Daniele Ricci commented 7 years ago

I can confirm the commit fixed the issue on the stable branch. Thanks!!

issue 1 of 1
Type
Bug
Priority
Major
Assignee
RedmineID
5859
Version
tigase-server-7.1.1
Spent time
2h 30m
Issue Votes (0)
Watchers (0)
Reference
tigase/_server/server-core#869
Please wait...
Page is in error, reload to recover