From 5ffa4eb1f2827c70db5078c39efb3f652b59a259 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Wed, 31 Aug 2011 14:03:28 +0000 Subject: [PATCH] #7479 WebSphere 8 class loading problem workaround (similar to old GlassFish 3.0.0 workaround) svn changeset:20778/svn branch:6.7 --- .../terminal/gwt/server/JsonPaintTarget.java | 110 +++++++++++------- 1 file changed, 67 insertions(+), 43 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java index 2f9a614b5f..28789b0ebc 100644 --- a/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java +++ b/src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java @@ -11,6 +11,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.Serializable; +import java.io.StringWriter; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -1040,65 +1041,88 @@ public class JsonPaintTarget implements PaintTarget { private boolean hasClientWidgetMapping(Class class1) { try { return class1.isAnnotationPresent(ClientWidget.class); + } catch (NoClassDefFoundError e) { + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + String stacktrace = writer.toString(); + if (stacktrace + .contains("com.ibm.oti.reflect.AnnotationParser.parseClass")) { + // #7479 IBM JVM apparently tries to eagerly load the classes + // referred to by annotations. Checking the annotation from byte + // code to be sure that we are dealing the this case and not + // some other class loading issue. + if (bytecodeContainsClientWidgetAnnotation(class1)) { + return true; + } + } else { + // throw exception forward + throw e; + } } catch (RuntimeException e) { if (e.getStackTrace()[0].getClassName().equals( "org.glassfish.web.loader.WebappClassLoader")) { + // See #3920 // Glassfish 3 is darn eager to load the value class, even // though we just want to check if the annotation exists. - // See #3920, remove this hack when fixed in glassfish + // In some situations (depending on class loading order) it // would be enough to return true here, but it is safer to check - // the annotation from bytecode + // the annotation from byte code - String name = class1.getName().replace('.', File.separatorChar) - + ".class"; + if (bytecodeContainsClientWidgetAnnotation(class1)) { + return true; + } + } else { + // throw exception forward + throw e; + } + } + return false; + } - try { - InputStream stream = class1.getClassLoader() - .getResourceAsStream(name); - BufferedReader bufferedReader = new BufferedReader( - new InputStreamReader(stream)); - try { - String line; - boolean atSourcefile = false; - while ((line = bufferedReader.readLine()) != null) { - if (line.startsWith("SourceFile")) { - atSourcefile = true; - } - if (atSourcefile) { - if (line.contains("ClientWidget")) { - return true; - } - } - // TODO could optize to quit at the end attribute - } - } catch (IOException e1) { - logger.log( - Level.SEVERE, - "An error occurred while finding widget mapping.", - e1); - } finally { - try { - bufferedReader.close(); - } catch (IOException e1) { - logger.log(Level.SEVERE, "Could not close reader.", - e1); + private boolean bytecodeContainsClientWidgetAnnotation( + Class class1) { + + try { + String name = class1.getName().replace('.', File.separatorChar) + + ".class"; + + InputStream stream = class1.getClassLoader().getResourceAsStream( + name); + BufferedReader bufferedReader = new BufferedReader( + new InputStreamReader(stream)); + try { + String line; + boolean atSourcefile = false; + while ((line = bufferedReader.readLine()) != null) { + if (line.startsWith("SourceFile")) { + atSourcefile = true; + } + if (atSourcefile) { + if (line.contains("ClientWidget")) { + return true; } } - - } catch (Throwable e2) { - logger.log(Level.SEVERE, - "An error occurred while finding widget mapping.", - e2); + // TODO could optimize to quit at the end attribute } + } catch (IOException e1) { + logger.log(Level.SEVERE, + "An error occurred while finding widget mapping.", e1); + } finally { + try { + bufferedReader.close(); + } catch (IOException e1) { + logger.log(Level.SEVERE, "Could not close reader.", e1); - return false; - } else { - // throw exception forward - throw e; + } } + } catch (Throwable t) { + logger.log(Level.SEVERE, + "An error occurred while finding widget mapping.", t); } + + return false; } Collection> getUsedPaintableTypes() { -- 2.39.5