Unfortunate Java Exception: java.lang.NoSuchMethodError
Asked Answered
A

3

7

I wrote an application, an it was working fine for 3 years, but! today when they try to run this application, an unexpected exception raised:

INFO   | jvm 1    | 2013/04/17 10:02:40 | Exception in thread "Thread-1" java.lang.NoSuchMethodError: java.sql.Connection.isValid(I)Z
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.MySQLConnectionPatch.SearchInCache(MySQLConnectionPatch.java:103)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.MySQLConnectionPatch.getConnection(MySQLConnectionPatch.java:79)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.SQLManager.establishSqlConnection(SQLManager.java:62)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.SQLManager.establishSqlConnection(SQLManager.java:30)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.tasks.classes.sql.executeQuery.execute(executeQuery.java:49)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at Components.TTask.run(TTask.java:86)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at Components.ThreadTask.run(ThreadTask.java:29)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.tasks.classes.fori.execute(fori.java:66)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at Components.TTask.run(TTask.java:86)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at Components.ThreadTask.run(ThreadTask.java:29)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at lib.tasks.classes.fori.execute(fori.java:66)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at Components.TTask.run(TTask.java:86)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at Components.ThreadTask.run(ThreadTask.java:29)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at Components.ThreadTask.run(ThreadTask.java:44)
INFO   | jvm 1    | 2013/04/17 10:02:40 |   at LauncherService.LaunchService.run(LaunchService.java:38)

code of MySQLConnectionPatch.java/SearchInCache is

private Connection SearchInCache(String key) {

    Connection result = null;
    try{
        if (!connections.isEmpty())
            result  = connections.get(key);
    } catch (Exception ex){
    }
    if (result != null){
        boolean isValid = false;  /** THIS IS LINE 103 WHERE EXCEPTION RAISED **/
        try {
            Statement s = result.createStatement();
            if (s.execute("SHOW STATUS;")){
                isValid = true;
            }
            s.close();
        } catch (Exception ex) {
            isValid = false;
        }

        if (!isValid){
            connections.remove(key);
            messageLog.stdwar("MySQL_PATCH: ONE CONNECTION EXPIRED :: force close");
            try {
                result.close();
            } catch (SQLException ex) {
                messageLog.stderr("MySQL_PATCH: CLOSING CONNECTION ERROR: "+ex.getMessage());
            }
            result = null;
        }
    }
    return result;
}

I wonder why boolean isValid = false; raise Exception java.lang.NoSuchMethodError: java.sql.Connection.isValid(I)Z.

Note that the only thing differs is JRE (former was 1.6, and the new is 1.7)

Aerophyte answered 17/4, 2013 at 6:42 Comment(10)
Application was working fine for 3 years and now crashes ? Something must have changed code/system/dependent libraryFoursquare
did you change the MySQL jdbc library ?Damick
Are you sure your application is using 1.7 and not 1.5 somehow? This method has only existed since 1.6.Ngocnguyen
Never EVER! let a catch block empty! what if an exception is even launched... will you ever be aware?Kilovolt
Looks like you are using an old version of the MySQL JDBC driver.Malar
Are you 100% certain that this is the code you are running? Could it not be a different version?Dinger
I like the word "unfortunate" in this question's title. That made me smile.Pollinosis
So when the isValid is removed everything is ok?Mcmanus
Try to delete all *class files and recompile them again with 1.7 compilerFlaccid
There is no chance in hell this is the source for the code you're running. Defining a boolean will never throw a NoSuchMethodError (this exception is only thrown when you are invoking a class part of a library and that version of the class does not contain that particular method). The sources you are showing are not for the compiled and running app. Make sure you're showing the proper source for that code.Per
A
0

Fixed!! And guess what! A copy of old jre (1.5.08) was embeded in HP Printer driver and the address was added to the PATH environment variable!

Aerophyte answered 6/5, 2013 at 14:42 Comment(1)
That's why I also use a jre for just one single project and start it with this one and not with any kind of system-default. Congratulations, that you found THAT ;-)Blancheblanchette
P
5

Odd. It's clearly referencing the isValid(int) method in java.sql.Connection

In your stacktrace I also see an I and a Z: java.sql.Connection.isValid(I)Z

Those correspond to int (I) and boolean (Z), the exact signature for the method in java.sql.Conneciton. So a method is definitely being called. Note: the character to the right of the parentheses indicates the method's return type, and this method returns boolean (Z).

Here are the only ideas I can think of:

  1. The source code you presented does not correspond to what's actually running in your environment. (e.g., maybe your "patch" is never really applied?)

  2. Also, your environment might be running Java 5, since the isValid(int) method does not show up until Java 6.

Pollinosis answered 17/4, 2013 at 6:52 Comment(0)
B
1

Sorry, I can't comment.

Did you just replace the jvm and none of your class-files? Please try your sources in an IDE (remember to replace also dependencies etc), so that you sources are recompiled and know about the new signatures that came with 1.7.

For the rest, I go with Julius Davies. Java should call isValid() (would be interesting, what happens, if you change it to boolean nameOtherThanAMethodOfConnection = false;).

Blancheblanchette answered 17/4, 2013 at 7:20 Comment(0)
A
0

Fixed!! And guess what! A copy of old jre (1.5.08) was embeded in HP Printer driver and the address was added to the PATH environment variable!

Aerophyte answered 6/5, 2013 at 14:42 Comment(1)
That's why I also use a jre for just one single project and start it with this one and not with any kind of system-default. Congratulations, that you found THAT ;-)Blancheblanchette

© 2022 - 2024 — McMap. All rights reserved.