Project

General

Profile

Bug #5859

DBSchemaLoader is not replicable for creating admin account

Added by Daniele Ricci almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
High
Assignee:
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:
Database:
n/a
Applicable version:
git/stable
Source Code Disclaimer:

Description

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.

History

#1 Updated by Andrzej Wójcik IoT 1 CloudTigaseTeam almost 2 years ago

  • Assignee set to Andrzej Wójcik

#2 Updated by Andrzej Wójcik IoT 1 CloudTigaseTeam almost 2 years ago

  • Status changed from New to In Progress

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.

#4 Updated by Daniele Ricci almost 2 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.

#5 Updated by Daniele Ricci almost 2 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!

#6 Updated by Andrzej Wójcik IoT 1 CloudTigaseTeam almost 2 years ago

  • Status changed from In Progress to In QA
  • Assignee changed from Andrzej Wójcik to Daniele Ricci
  • % Done changed from 0 to 100

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@.

#7 Updated by Daniele Ricci almost 2 years ago

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

#8 Updated by Andrzej Wójcik IoT 1 CloudTigaseTeam almost 2 years ago

  • Status changed from In QA to Closed

Also available in: Atom PDF