Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 and exclude the JPA, JAX-WS and EJB annotations completely from the Tomcat distributions.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1810106 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Sep 29, 2017
1 parent 7cec82e commit ba298d8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 29 deletions.
3 changes: 0 additions & 3 deletions build.xml
Expand Up @@ -296,9 +296,6 @@
<!-- Pattern sets for jar files in standard distributions --> <!-- Pattern sets for jar files in standard distributions -->
<patternset id="files.annotations-api"> <patternset id="files.annotations-api">
<include name="javax/annotation/**" /> <include name="javax/annotation/**" />
<include name="javax/ejb/**" />
<include name="javax/persistence/**" />
<include name="javax/xml/ws/**" />
</patternset> </patternset>


<patternset id="files.servlet-api"> <patternset id="files.servlet-api">
Expand Down
84 changes: 58 additions & 26 deletions java/org/apache/catalina/core/DefaultInstanceManager.java
Expand Up @@ -67,6 +67,37 @@ public class DefaultInstanceManager implements InstanceManager {
protected static final StringManager sm = protected static final StringManager sm =
StringManager.getManager(Constants.Package); StringManager.getManager(Constants.Package);


private static final boolean EJB_PRESENT;
private static final boolean JPA_PRESENT;
private static final boolean WS_PRESENT;

static {
Class<?> clazz = null;
try {
clazz = Class.forName("javax.ejb.EJB");
} catch (ClassNotFoundException cnfe) {
// Expected
}
EJB_PRESENT = (clazz != null);

clazz = null;
try {
clazz = Class.forName("javax.persistence.PersistenceContext");
} catch (ClassNotFoundException cnfe) {
// Expected
}
JPA_PRESENT = (clazz != null);

clazz = null;
try {
clazz = Class.forName("javax.xml.ws.WebServiceRef");
} catch (ClassNotFoundException cnfe) {
// Expected
}
WS_PRESENT = (clazz != null);
}


private final Context context; private final Context context;
private final Map<String, Map<String, String>> injectionMap; private final Map<String, Map<String, String>> injectionMap;
protected final ClassLoader classLoader; protected final ClassLoader classLoader;
Expand Down Expand Up @@ -283,10 +314,10 @@ protected void populateAnnotationsCache(Class<?> clazz,
Field[] fields = Introspection.getDeclaredFields(clazz); Field[] fields = Introspection.getDeclaredFields(clazz);
for (Field field : fields) { for (Field field : fields) {
Resource resourceAnnotation; Resource resourceAnnotation;
EJB ejbAnnotation; Annotation ejbAnnotation;
WebServiceRef webServiceRefAnnotation; Annotation webServiceRefAnnotation;
PersistenceContext persistenceContextAnnotation; Annotation persistenceContextAnnotation;
PersistenceUnit persistenceUnitAnnotation; Annotation persistenceUnitAnnotation;
if (injections != null && injections.containsKey(field.getName())) { if (injections != null && injections.containsKey(field.getName())) {
annotations.add(new AnnotationCacheEntry( annotations.add(new AnnotationCacheEntry(
field.getName(), null, field.getName(), null,
Expand All @@ -296,24 +327,24 @@ protected void populateAnnotationsCache(Class<?> clazz,
field.getAnnotation(Resource.class)) != null) { field.getAnnotation(Resource.class)) != null) {
annotations.add(new AnnotationCacheEntry(field.getName(), null, annotations.add(new AnnotationCacheEntry(field.getName(), null,
resourceAnnotation.name(), AnnotationCacheEntryType.FIELD)); resourceAnnotation.name(), AnnotationCacheEntryType.FIELD));
} else if ((ejbAnnotation = } else if (EJB_PRESENT &&
field.getAnnotation(EJB.class)) != null) { (ejbAnnotation = field.getAnnotation(EJB.class)) != null) {
annotations.add(new AnnotationCacheEntry(field.getName(), null, annotations.add(new AnnotationCacheEntry(field.getName(), null,
ejbAnnotation.name(), AnnotationCacheEntryType.FIELD)); ((EJB) ejbAnnotation).name(), AnnotationCacheEntryType.FIELD));
} else if ((webServiceRefAnnotation = } else if (WS_PRESENT && (webServiceRefAnnotation =
field.getAnnotation(WebServiceRef.class)) != null) { field.getAnnotation(WebServiceRef.class)) != null) {
annotations.add(new AnnotationCacheEntry(field.getName(), null, annotations.add(new AnnotationCacheEntry(field.getName(), null,
webServiceRefAnnotation.name(), ((WebServiceRef) webServiceRefAnnotation).name(),
AnnotationCacheEntryType.FIELD)); AnnotationCacheEntryType.FIELD));
} else if ((persistenceContextAnnotation = } else if (JPA_PRESENT && (persistenceContextAnnotation =
field.getAnnotation(PersistenceContext.class)) != null) { field.getAnnotation(PersistenceContext.class)) != null) {
annotations.add(new AnnotationCacheEntry(field.getName(), null, annotations.add(new AnnotationCacheEntry(field.getName(), null,
persistenceContextAnnotation.name(), ((PersistenceContext) persistenceContextAnnotation).name(),
AnnotationCacheEntryType.FIELD)); AnnotationCacheEntryType.FIELD));
} else if ((persistenceUnitAnnotation = } else if (JPA_PRESENT && (persistenceUnitAnnotation =
field.getAnnotation(PersistenceUnit.class)) != null) { field.getAnnotation(PersistenceUnit.class)) != null) {
annotations.add(new AnnotationCacheEntry(field.getName(), null, annotations.add(new AnnotationCacheEntry(field.getName(), null,
persistenceUnitAnnotation.name(), ((PersistenceUnit) persistenceUnitAnnotation).name(),
AnnotationCacheEntryType.FIELD)); AnnotationCacheEntryType.FIELD));
} }
} }
Expand Down Expand Up @@ -341,43 +372,44 @@ protected void populateAnnotationsCache(Class<?> clazz,
} }
} }
Resource resourceAnnotation; Resource resourceAnnotation;
EJB ejbAnnotation; Annotation ejbAnnotation;
WebServiceRef webServiceRefAnnotation; Annotation webServiceRefAnnotation;
PersistenceContext persistenceContextAnnotation; Annotation persistenceContextAnnotation;
PersistenceUnit persistenceUnitAnnotation; Annotation persistenceUnitAnnotation;
if ((resourceAnnotation = if ((resourceAnnotation =
method.getAnnotation(Resource.class)) != null) { method.getAnnotation(Resource.class)) != null) {
annotations.add(new AnnotationCacheEntry( annotations.add(new AnnotationCacheEntry(
method.getName(), method.getName(),
method.getParameterTypes(), method.getParameterTypes(),
resourceAnnotation.name(), resourceAnnotation.name(),
AnnotationCacheEntryType.SETTER)); AnnotationCacheEntryType.SETTER));
} else if ((ejbAnnotation = } else if (EJB_PRESENT &&
method.getAnnotation(EJB.class)) != null) { (ejbAnnotation = method.getAnnotation(EJB.class)) != null) {
annotations.add(new AnnotationCacheEntry( annotations.add(new AnnotationCacheEntry(
method.getName(), method.getName(),
method.getParameterTypes(), method.getParameterTypes(),
ejbAnnotation.name(), ((EJB) ejbAnnotation).name(),
AnnotationCacheEntryType.SETTER)); AnnotationCacheEntryType.SETTER));
} else if ((webServiceRefAnnotation = } else if (WS_PRESENT && (webServiceRefAnnotation =
method.getAnnotation(WebServiceRef.class)) != null) { method.getAnnotation(WebServiceRef.class)) != null) {
annotations.add(new AnnotationCacheEntry( annotations.add(new AnnotationCacheEntry(
method.getName(), method.getName(),
method.getParameterTypes(), method.getParameterTypes(),
webServiceRefAnnotation.name(), ((WebServiceRef) webServiceRefAnnotation).name(),
AnnotationCacheEntryType.SETTER)); AnnotationCacheEntryType.SETTER));
} else if ((persistenceContextAnnotation = } else if (JPA_PRESENT && (persistenceContextAnnotation =
method.getAnnotation(PersistenceContext.class)) != null) { method.getAnnotation(PersistenceContext.class)) != null) {
annotations.add(new AnnotationCacheEntry( annotations.add(new AnnotationCacheEntry(
method.getName(), method.getName(),
method.getParameterTypes(), method.getParameterTypes(),
persistenceContextAnnotation.name(), ((PersistenceContext) persistenceContextAnnotation).name(),
AnnotationCacheEntryType.SETTER)); AnnotationCacheEntryType.SETTER));
} else if ((persistenceUnitAnnotation = method.getAnnotation(PersistenceUnit.class)) != null) { } else if (JPA_PRESENT && (persistenceUnitAnnotation =
method.getAnnotation(PersistenceUnit.class)) != null) {
annotations.add(new AnnotationCacheEntry( annotations.add(new AnnotationCacheEntry(
method.getName(), method.getName(),
method.getParameterTypes(), method.getParameterTypes(),
persistenceUnitAnnotation.name(), ((PersistenceUnit) persistenceUnitAnnotation).name(),
AnnotationCacheEntryType.SETTER)); AnnotationCacheEntryType.SETTER));
} }
} }
Expand Down
6 changes: 6 additions & 0 deletions webapps/docs/changelog.xml
Expand Up @@ -45,6 +45,12 @@
issues do not "pop up" wrt. others). issues do not "pop up" wrt. others).
--> -->
<section name="Tomcat 9.0.2 (markt)" rtext="in development"> <section name="Tomcat 9.0.2 (markt)" rtext="in development">
<subsection name="Other">
<fix>
Improve the fix for <bug>61439</bug> and exclude the JPA, JAX-WS and EJB
annotations completely from the Tomcat distributions. (markt)
</fix>
</subsection>
</section> </section>
<section name="Tomcat 9.0.1 (markt)" rtext="release in progress"> <section name="Tomcat 9.0.1 (markt)" rtext="release in progress">
<subsection name="Catalina"> <subsection name="Catalina">
Expand Down

0 comments on commit ba298d8

Please sign in to comment.