diff --git a/common/pom.xml b/common/pom.xml
index 1e6ba30edb..29bd4b12f7 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -30,13 +30,6 @@
Netty/Common
-
-
- org.javassist
- javassist
- compile
- true
-
org.jctools
jctools-core
diff --git a/common/src/main/java/io/netty/util/internal/JavassistTypeParameterMatcherGenerator.java b/common/src/main/java/io/netty/util/internal/JavassistTypeParameterMatcherGenerator.java
deleted file mode 100644
index 2977ea14c5..0000000000
--- a/common/src/main/java/io/netty/util/internal/JavassistTypeParameterMatcherGenerator.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2013 The Netty Project
- *
- * The Netty Project licenses this file to you under the Apache License,
- * version 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package io.netty.util.internal;
-
-import io.netty.util.internal.logging.InternalLogger;
-import io.netty.util.internal.logging.InternalLoggerFactory;
-import javassist.ClassClassPath;
-import javassist.ClassPath;
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.Modifier;
-import javassist.NotFoundException;
-
-import java.lang.reflect.Method;
-
-public final class JavassistTypeParameterMatcherGenerator {
-
- private static final InternalLogger logger =
- InternalLoggerFactory.getInstance(JavassistTypeParameterMatcherGenerator.class);
-
- private static final ClassPool classPool = new ClassPool(true);
-
- static {
- classPool.appendClassPath(new ClassClassPath(NoOpTypeParameterMatcher.class));
- }
-
- public static void appendClassPath(ClassPath classpath) {
- classPool.appendClassPath(classpath);
- }
-
- public static void appendClassPath(String pathname) throws NotFoundException {
- classPool.appendClassPath(pathname);
- }
-
- public static TypeParameterMatcher generate(Class> type) {
- ClassLoader classLoader = PlatformDependent.getContextClassLoader();
- if (classLoader == null) {
- classLoader = PlatformDependent.getSystemClassLoader();
- }
- return generate(type, classLoader);
- }
-
- public static TypeParameterMatcher generate(Class> type, ClassLoader classLoader) {
- final String typeName = typeName(type);
- final String className = "io.netty.util.internal.__matchers__." + typeName + "Matcher";
- try {
- try {
- return (TypeParameterMatcher) Class.forName(className, true, classLoader).newInstance();
- } catch (Exception e) {
- // Not defined in the specified class loader.
- }
-
- CtClass c = classPool.getAndRename(NoOpTypeParameterMatcher.class.getName(), className);
- c.setModifiers(c.getModifiers() | Modifier.FINAL);
- c.getDeclaredMethod("match").setBody("{ return $1 instanceof " + typeName + "; }");
- byte[] byteCode = c.toBytecode();
- c.detach();
- Method method = ClassLoader.class.getDeclaredMethod(
- "defineClass", String.class, byte[].class, int.class, int.class);
- method.setAccessible(true);
-
- Class> generated = (Class>) method.invoke(classLoader, className, byteCode, 0, byteCode.length);
- if (type != Object.class) {
- logger.debug("Generated: {}", generated.getName());
- } else {
- // Object.class is only used when checking if Javassist is available.
- }
- return (TypeParameterMatcher) generated.newInstance();
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- private static String typeName(Class> type) {
- if (type.isArray()) {
- return typeName(type.getComponentType()) + "[]";
- }
-
- return type.getName();
- }
-
- private JavassistTypeParameterMatcherGenerator() { }
-}
diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent.java b/common/src/main/java/io/netty/util/internal/PlatformDependent.java
index 41b2d2ee44..39c80ca532 100644
--- a/common/src/main/java/io/netty/util/internal/PlatformDependent.java
+++ b/common/src/main/java/io/netty/util/internal/PlatformDependent.java
@@ -93,8 +93,6 @@ public final class PlatformDependent {
private static final long ARRAY_BASE_OFFSET = arrayBaseOffset0();
- private static final boolean HAS_JAVASSIST = hasJavassist0();
-
private static final File TMPDIR = tmpdir0();
private static final int BIT_MODE = bitMode0();
@@ -238,13 +236,6 @@ public final class PlatformDependent {
return MAX_DIRECT_MEMORY;
}
- /**
- * Returns {@code true} if and only if Javassist is available.
- */
- public static boolean hasJavassist() {
- return HAS_JAVASSIST;
- }
-
/**
* Returns the temporary directory.
*/
@@ -932,33 +923,6 @@ public final class PlatformDependent {
return maxDirectMemory;
}
- private static boolean hasJavassist0() {
- if (isAndroid()) {
- return false;
- }
-
- boolean noJavassist = SystemPropertyUtil.getBoolean("io.netty.noJavassist", false);
- logger.debug("-Dio.netty.noJavassist: {}", noJavassist);
-
- if (noJavassist) {
- logger.debug("Javassist: unavailable (io.netty.noJavassist)");
- return false;
- }
-
- try {
- JavassistTypeParameterMatcherGenerator.generate(Object.class, getClassLoader(PlatformDependent.class));
- logger.debug("Javassist: available");
- return true;
- } catch (Throwable t) {
- // Failed to generate a Javassist-based matcher.
- logger.debug("Javassist: unavailable");
- logger.debug(
- "You don't have Javassist in your class path or you don't have enough permission " +
- "to load dynamically generated classes. Please check the configuration for better performance.");
- return false;
- }
- }
-
private static File tmpdir0() {
File f;
try {
diff --git a/common/src/main/java/io/netty/util/internal/TypeParameterMatcher.java b/common/src/main/java/io/netty/util/internal/TypeParameterMatcher.java
index a10b149d78..f76e6719f3 100644
--- a/common/src/main/java/io/netty/util/internal/TypeParameterMatcher.java
+++ b/common/src/main/java/io/netty/util/internal/TypeParameterMatcher.java
@@ -26,8 +26,12 @@ import java.util.Map;
public abstract class TypeParameterMatcher {
- private static final TypeParameterMatcher NOOP = new NoOpTypeParameterMatcher();
- private static final Object TEST_OBJECT = new Object();
+ private static final TypeParameterMatcher NOOP = new TypeParameterMatcher() {
+ @Override
+ public boolean match(Object msg) {
+ return true;
+ }
+ };
public static TypeParameterMatcher get(final Class> parameterType) {
final Map, TypeParameterMatcher> getCache =
@@ -37,23 +41,9 @@ public abstract class TypeParameterMatcher {
if (matcher == null) {
if (parameterType == Object.class) {
matcher = NOOP;
- } else if (PlatformDependent.hasJavassist()) {
- try {
- matcher = JavassistTypeParameterMatcherGenerator.generate(parameterType);
- matcher.match(TEST_OBJECT);
- } catch (IllegalAccessError e) {
- // Happens if parameterType is not public.
- matcher = null;
- } catch (Exception e) {
- // Will not usually happen, but just in case.
- matcher = null;
- }
- }
-
- if (matcher == null) {
+ } else {
matcher = new ReflectiveMatcher(parameterType);
}
-
getCache.put(parameterType, matcher);
}
@@ -172,5 +162,5 @@ public abstract class TypeParameterMatcher {
}
}
- protected TypeParameterMatcher() { }
+ TypeParameterMatcher() { }
}