Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 211128 Details for
Bug 371793
@javax.annotation.Nonnull on constructor args causes bad class file / bad signature error when javac tries to use a woven class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
swing checking aspect, CheckSwing.aj
CheckSwing.aj (text/plain), 9.25 KB, created by
Matt McHenry
on 2012-02-16 12:02:26 EST
(
hide
)
Description:
swing checking aspect, CheckSwing.aj
Filename:
MIME Type:
Creator:
Matt McHenry
Created:
2012-02-16 12:02:26 EST
Size:
9.25 KB
patch
obsolete
>// ********************************************************************* >// >// Copyright (C) 2003 >// Carnegie Learning Inc. >// >// All Rights Reserved. >// >// This program is the subject of trade secrets and intellectual >// property rights owned by Carnegie Learning. >// >// This legend must continue to appear in the source code despite >// modifications or enhancements by any party. >// >// ********************************************************************* > >package cl.utilities; > >import java.awt.Component; >import java.net.URL; >import java.util.concurrent.ConcurrentHashMap; >import java.util.concurrent.ConcurrentMap; >import java.util.concurrent.atomic.AtomicInteger; > >import javax.swing.RepaintManager; >import javax.swing.SwingUtilities; > >import cl.utilities.Logging.Logger; > >/** > * This aspect logs any potential unsafe calls to Swing methods.<br> > * > * Since Swing is not thread-safe, it is unsafe to call any swing > * method that alters the state of the user interface from any thread except > * the Event Dispatch thread. This aspect attempts to catch any such > * unsafe call and log it for later analysis.<br> > * > * For more info on thread-safety in Swing, see > * http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html<br> > * > * To see an explanation of a sample aspect that attempts to detect this > * situation, see > * http://www.javaworld.com/javaworld/jw-03-2002/jw-0301-aspect2.html?page=4 > * <br> > * > * For info on using AspsectJ at Carnegie Learning, see the svn folder > * trunk/doc/Software/Development Environment/AspectJ/ > * <br> > * > * Bug 17921 was the original motivation for this aspect.<br> > * > * Bug 17930 tracks the progress of this aspect.<br> > * > * @author Mike Schneider > * @author kschaefer (version 2.0) > * @version 2.0 > */ >@SuppressWarnings("nls") >public aspect CheckSwing { > static enum CheckLevel { > /** > * Only validates that components are invoked on the EDT, if the component is displayable. > */ > WEAK, > > /** > * Ensures that components are created and called on the EDT. > */ > MEDIUM, > > /** > * Ensures that components and Swing models are created and called on the EDT. > */ > STRICT; > > private static CheckLevel currentLevel; > > public static CheckLevel getCurrentLevel() { > if (currentLevel == null) { > return valueOf(System.getProperty("cl.swingcheck.level", STRICT.name())); > } > > return currentLevel; > } > > static void setCurrentLevel(CheckLevel currentLevel) { > CheckLevel.currentLevel = currentLevel; > } > } > > /** > * Used to disable the prevention of duplicates. > * <p> > * This is necessary for the JUnit test to run correctly. > */ > private static volatile boolean ignoreDuplicateViolations = true; > > /** > * Used to disable the logging of exception and cause them to be thrown. > * <p> > * This is necessary for the JUnit test to run correctly. > */ > private static volatile boolean logViolations = true; > > /** > * counts the number of times swing methods have been called unsafely > */ > private final AtomicInteger count = new AtomicInteger(1); > > /** > * tracks the call signature/thread combination to eliminate duplicate logging > */ > private final ConcurrentMap<String, Boolean> keySet = new ConcurrentHashMap<String, Boolean>(); > > pointcut componentCalls(): > call (javax.swing.JComponent+.new(..)) || > call (javax.swing.JWindow+.new(..)) || > call (javax.swing.JFrame+.new(..)) || > call (javax.swing.JDialog+.new(..)) || > //ignore static methods; TODO is that correct? > call (!static * javax.swing.JComponent+.*(..)) || > call (!static * javax.swing.JWindow+.*(..)) || > call (!static * javax.swing.JFrame+.*(..)) || > call (!static * javax.swing.JDialog+.*(..)); > > pointcut modelCalls(): > call (javax..*Model+.new(..)) || > call (javax.swing.text.Document+.new(..)) || > call (!static * javax..*Model+.*(..)) || > call (!static * javax.swing.text.Document+.*(..)); > > pointcut threadSafeCalls() : > //synchronized methods are thread safe! > call (synchronized * javax.swing.JComponent+.*(..)) || > > //per http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html > call (void javax.swing.JComponent.revalidate()) || > call (void javax.swing.JComponent.invalidate()) || > call (void javax.swing.JComponent.repaint(..)) || > call (void add*Listener(java.util.EventListener+)) || > call (void remove*Listener(java.util.EventListener+)) || > > //per class documentation; there may be others, check before filing bugs > call (void javax.swing.text.JTextComponent.replaceSelection(String)) || > call (void javax.swing.text.JTextComponent.setText(String)) || > call (boolean javax.swing.text.JTextComponent.print(..)) || > > //implicitly-safe, cf. Bug 29580 > cflowbelow (call (void javax.swing.RepaintManager.addDirtyRegion(..))) || > > //we consider these possibly dirty reads OK > call (String javax.swing..*.toString()) || > call (String javax.swing..*.toShortDebugString()) || > call (String java.awt.Component.getName()) || > call (* javax.swing..*.getMessagingParent()) || > call (URL javax.swing.text.html.HTMLDocument.getBase()); > > /** > * Advice to enable the WEAK and MEDIUM checking levels. > * <p> > * The STRONG checking level is implemented partially here with the model checks in another > * piece of advice. > */ > before() : componentCalls() && !threadSafeCalls() { > if (SwingUtilities.isEventDispatchThread()) { > return; > } > > //this exception is a hack, but I can't get within or cflowbelow to do what I want > StackTraceElement[] stackTrace = new Exception().getStackTrace(); > String clazz = stackTrace.length < 2 ? null : stackTrace[2].getClassName(); > > if (RepaintManager.class.getName().equals(clazz) || "org.jdesktop.swingx.RepaintManagerX".equals(clazz)) { > return; > } > > Component target = (Component) thisJoinPoint.getTarget(); > > switch (CheckLevel.getCurrentLevel()) { > case STRICT: > //falls through > case MEDIUM: > logSignature(thisJoinPoint.getSignature().toString()); > break; > case WEAK: > //if the component is displayable; then we need to bark > //components are made displayable when they are packed or a TLA becomes visible > if (target != null && target.isDisplayable()) { > logSignature(thisJoinPoint.getSignature().toString()); > } > > break; > default: > throw new IllegalStateException("unknown CheckLevel"); > } > } > > /** > * Advice to enable the WEAK and MEDIUM checking levels. > * <p> > * The STRONG checking level is implemented partially here with the model checks in another > * piece of advice. > */ > before() : modelCalls() && !threadSafeCalls() { > if (SwingUtilities.isEventDispatchThread()) { > return; > } > > switch (CheckLevel.getCurrentLevel()) { > case STRICT: > logSignature(thisJoinPoint.getSignature().toString()); > break; > case MEDIUM: > //falls through > case WEAK: > //does nothing > break; > default: > throw new IllegalStateException("unknown CheckLevel"); > } > } > > static boolean isIgnoreDuplicateViolations() { > return ignoreDuplicateViolations; > } > > static void setIgnoreDuplicateViolations(boolean ignoreDuplicateViolations) { > CheckSwing.ignoreDuplicateViolations = ignoreDuplicateViolations; > } > > static boolean isLogViolations() { > return logViolations; > } > > static void setLogViolations(boolean logViolations) { > CheckSwing.logViolations = logViolations; > } > > /** > * Log the violation, if it's a new one. > * @param signature > */ > private void logSignature(String signature) { > // Check to see if we've seen this thread/signature combination before > // If so, don't log it > String thread = Thread.currentThread().getName(); > String key = signature + thread; > > if (isIgnoreDuplicateViolations() && keySet.putIfAbsent(key, Boolean.TRUE) != null) { > return; > } > > String string = " Calling method " + signature + " from outside EDT"; > String output = count.getAndIncrement() > + ": Bug 17930 violation: create new bug as appropriate. " + string; > > if (isLogViolations()) { > if (Logger.isLoggingOn()) { > Logger.log(new AWT_EventThreadViolation(output)); > } > } else { > throw new AWT_EventThreadViolation(output); > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 371793
:
211127
| 211128