Skip to content

Commit

Permalink
Fix for Bug#34918989, Pluggable classes are initialized even when the…
Browse files Browse the repository at this point in the history
…y cannot be used by Connector/J.

Change-Id: I7b96bc52d0f2e6a77ef1623bf10644c7ca5b7bb4
  • Loading branch information
fjssilva committed Mar 2, 2023
1 parent e4c68b3 commit 2b16eed
Show file tree
Hide file tree
Showing 25 changed files with 361 additions and 466 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.0.33

- Fix for Bug#34918989, Pluggable classes are initialized even when they cannot be used by Connector/J.

- Fix for Bug#93415 (Bug#28992710), Documentation for getDefaultSchema() Needs Improvements.

- Fix for Bug#110168 (Bug#35110706), yum update fails upgrading Connector/J package.
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/java/com/mysql/jdbc/SocketFactoryWrapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates.
* Copyright (c) 2018, 2023, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -48,8 +48,8 @@ public class SocketFactoryWrapper extends StandardSocketFactory implements Socke
com.mysql.jdbc.SocketFactory socketFactory;

@SuppressWarnings("deprecation")
public SocketFactoryWrapper(Object legacyFactory) {
this.socketFactory = (com.mysql.jdbc.SocketFactory) legacyFactory;
public SocketFactoryWrapper(com.mysql.jdbc.SocketFactory legacyFactory) {
this.socketFactory = legacyFactory;
}

@SuppressWarnings({ "deprecation", "unchecked" })
Expand Down
11 changes: 5 additions & 6 deletions src/main/core-api/java/com/mysql/cj/conf/ConnectionUrl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
* Copyright (c) 2016, 2023, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -238,7 +238,7 @@ public static boolean isSupported(String scheme) {
* an instance of {@link ConnectionUrl}.
*/
private ConnectionUrl getImplementingInstance(ConnectionUrlParser parser, Properties info) {
return (ConnectionUrl) Util.getInstance(getImplementingClass(), new Class<?>[] { ConnectionUrlParser.class, Properties.class },
return Util.getInstance(ConnectionUrl.class, this.implementingClass, new Class<?>[] { ConnectionUrlParser.class, Properties.class },
new Object[] { parser, info }, null);
}
}
Expand Down Expand Up @@ -379,10 +379,9 @@ protected void setupPropertiesTransformer() {
String propertiesTransformClassName = this.properties.get(PropertyKey.propertiesTransform.getKeyName());
if (!isNullOrEmpty(propertiesTransformClassName)) {
try {
this.propertiesTransformer = (ConnectionPropertiesTransform) Class.forName(propertiesTransformClassName).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | CJException e) {
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class,
Messages.getString("ConnectionString.9", new Object[] { propertiesTransformClassName, e.toString() }), e);
this.propertiesTransformer = Util.getInstance(ConnectionPropertiesTransform.class, propertiesTransformClassName, null, null, null);
} catch (CJException e) {
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class, Messages.getString("ConnectionString.9"), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates.
* Copyright (c) 2015, 2023, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -30,14 +30,15 @@
package com.mysql.cj.exceptions;

import java.net.BindException;
import java.net.NetworkInterface;
import java.net.SocketException;

import com.mysql.cj.Messages;
import com.mysql.cj.conf.PropertyKey;
import com.mysql.cj.conf.PropertySet;
import com.mysql.cj.protocol.PacketReceivedTimeHolder;
import com.mysql.cj.protocol.PacketSentTimeHolder;
import com.mysql.cj.protocol.ServerSession;
import com.mysql.cj.util.Util;

public class ExceptionFactory {

Expand Down Expand Up @@ -101,9 +102,7 @@ public static CJException createException(String message, Throwable cause) {
}

public static <T extends CJException> T createException(Class<T> clazz, String message, Throwable cause) {

T sqlEx = createException(clazz, message);

if (cause != null) {
try {
sqlEx.initCause(cause);
Expand Down Expand Up @@ -282,8 +281,13 @@ public static String createLinkFailureMessageBasedOnHeuristics(PropertySet prope
//
if (underlyingException instanceof BindException) {
String localSocketAddress = propertySet.getStringProperty(PropertyKey.localSocketAddress).getValue();
exceptionMessageBuf.append(localSocketAddress != null && !Util.interfaceExists(localSocketAddress)
? Messages.getString("CommunicationsException.LocalSocketAddressNotAvailable")
boolean interfaceNotAvaliable;
try {
interfaceNotAvaliable = localSocketAddress != null && NetworkInterface.getByName(localSocketAddress) == null;
} catch (SocketException e1) {
interfaceNotAvaliable = false;
}
exceptionMessageBuf.append(interfaceNotAvaliable ? Messages.getString("CommunicationsException.LocalSocketAddressNotAvailable")
: Messages.getString("CommunicationsException.TooManyClientConnections"));
}
}
Expand All @@ -303,5 +307,4 @@ public static String createLinkFailureMessageBasedOnHeuristics(PropertySet prope

return exceptionMessageBuf.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -29,7 +29,7 @@

package com.mysql.cj.exceptions;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
Expand All @@ -38,53 +38,34 @@
import com.mysql.cj.util.Util;

public class ExceptionInterceptorChain implements ExceptionInterceptor {
List<ExceptionInterceptor> interceptors;
private List<ExceptionInterceptor> interceptors;

public ExceptionInterceptorChain(String interceptorClasses, Properties props, Log log) {
this.interceptors = Util.<ExceptionInterceptor> loadClasses(interceptorClasses, "Connection.BadExceptionInterceptor", this).stream()
.map(o -> o.init(props, log)).collect(Collectors.toList());
this.interceptors = Util.loadClasses(ExceptionInterceptor.class, interceptorClasses, "Connection.BadExceptionInterceptor", null).stream()
.map(i -> i.init(props, log)).collect(Collectors.toCollection(LinkedList::new));
}

public void addRingZero(ExceptionInterceptor interceptor) {
this.interceptors.add(0, interceptor);
}

public Exception interceptException(Exception sqlEx) {
if (this.interceptors != null) {
Iterator<ExceptionInterceptor> iter = this.interceptors.iterator();

while (iter.hasNext()) {
sqlEx = iter.next().interceptException(sqlEx);
}
for (ExceptionInterceptor ie : this.interceptors) {
sqlEx = ie.interceptException(sqlEx);
}

return sqlEx;
}

public void destroy() {
if (this.interceptors != null) {
Iterator<ExceptionInterceptor> iter = this.interceptors.iterator();

while (iter.hasNext()) {
iter.next().destroy();
}
}

this.interceptors.forEach(ExceptionInterceptor::destroy);
}

public ExceptionInterceptor init(Properties properties, Log log) {
if (this.interceptors != null) {
Iterator<ExceptionInterceptor> iter = this.interceptors.iterator();

while (iter.hasNext()) {
iter.next().init(properties, log);
}
}
this.interceptors = this.interceptors.stream().map(i -> i.init(properties, log)).collect(Collectors.toCollection(LinkedList::new));
return this;
}

public List<ExceptionInterceptor> getInterceptors() {
return this.interceptors;
}

}
Loading

0 comments on commit 2b16eed

Please sign in to comment.