提交 2675edec 编写于 作者: M malenkov

8043627: NPE in SynthContext in plugin mode

Reviewed-by: alexsch, serb, pchelko
上级 940a1c7b
......@@ -138,9 +138,7 @@ public class SynthButtonUI extends BasicButtonUI implements
}
SynthContext getContext(JComponent c, int state) {
Region region = SynthLookAndFeel.getRegion(c);
return SynthContext.getContext(SynthContext.class, c, region,
style, state);
return SynthContext.getContext(c, style, state);
}
/**
......
......@@ -128,8 +128,7 @@ public class SynthColorChooserUI extends BasicColorChooserUI implements
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -208,8 +208,7 @@ public class SynthComboBoxUI extends BasicComboBoxUI implements
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -24,9 +24,9 @@
*/
package javax.swing.plaf.synth;
import javax.swing.*;
import java.util.*;
import sun.reflect.misc.ReflectUtil;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.swing.JComponent;
/**
* An immutable transient object containing contextual information about
......@@ -40,59 +40,32 @@ import sun.reflect.misc.ReflectUtil;
* @author Scott Violet
*/
public class SynthContext {
private static final Map<Class, List<SynthContext>> contextMap;
private static final Queue<SynthContext> queue = new ConcurrentLinkedQueue<>();
private JComponent component;
private Region region;
private SynthStyle style;
private int state;
static {
contextMap = new HashMap<Class, List<SynthContext>>();
static SynthContext getContext(JComponent c, SynthStyle style, int state) {
return getContext(c, SynthLookAndFeel.getRegion(c), style, state);
}
static SynthContext getContext(Class type, JComponent component,
static SynthContext getContext(JComponent component,
Region region, SynthStyle style,
int state) {
SynthContext context = null;
synchronized(contextMap) {
List<SynthContext> instances = contextMap.get(type);
if (instances != null) {
int size = instances.size();
if (size > 0) {
context = instances.remove(size - 1);
}
}
}
SynthContext context = queue.poll();
if (context == null) {
try {
context = (SynthContext) ReflectUtil.newInstance(type);
} catch (IllegalAccessException iae) {
} catch (InstantiationException ie) {
}
context = new SynthContext();
}
context.reset(component, region, style, state);
return context;
}
static void releaseContext(SynthContext context) {
synchronized(contextMap) {
List<SynthContext> instances = contextMap.get(context.getClass());
if (instances == null) {
instances = new ArrayList<SynthContext>(5);
contextMap.put(context.getClass(), instances);
}
instances.add(context);
}
queue.offer(context);
}
SynthContext() {
}
......
......@@ -142,9 +142,7 @@ public class SynthDesktopIconUI extends BasicDesktopIconUI
}
private SynthContext getContext(JComponent c, int state) {
Region region = SynthLookAndFeel.getRegion(c);
return SynthContext.getContext(SynthContext.class, c, region,
style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -430,8 +430,7 @@ public class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -139,8 +139,7 @@ public class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI {
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -67,8 +67,7 @@ class SynthInternalFrameTitlePane extends BasicInternalFrameTitlePane
}
public SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private Region getRegion(JComponent c) {
......
......@@ -141,8 +141,7 @@ public class SynthInternalFrameUI extends BasicInternalFrameUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -91,8 +91,7 @@ public class SynthLabelUI extends BasicLabelUI implements SynthUI {
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -188,8 +188,7 @@ public class SynthListUI extends BasicListUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -116,8 +116,7 @@ public class SynthMenuBarUI extends BasicMenuBarUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -170,8 +170,7 @@ public class SynthMenuItemUI extends BasicMenuItemUI implements
}
SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
SynthContext getContext(JComponent c, Region region) {
......@@ -179,8 +178,7 @@ public class SynthMenuItemUI extends BasicMenuItemUI implements
}
private SynthContext getContext(JComponent c, Region region, int state) {
return SynthContext.getContext(SynthContext.class, c,
region, accStyle, state);
return SynthContext.getContext(c, region, accStyle, state);
}
private int getComponentState(JComponent c) {
......
......@@ -170,9 +170,7 @@ public class SynthMenuUI extends BasicMenuUI
}
SynthContext getContext(JComponent c, int state) {
Region region = SynthLookAndFeel.getRegion(c);
return SynthContext.getContext(SynthContext.class, c, region,
style, state);
return SynthContext.getContext(c, style, state);
}
SynthContext getContext(JComponent c, Region region) {
......@@ -180,8 +178,7 @@ public class SynthMenuUI extends BasicMenuUI
}
private SynthContext getContext(JComponent c, Region region, int state) {
return SynthContext.getContext(SynthContext.class, c,
region, accStyle, state);
return SynthContext.getContext(c, region, accStyle, state);
}
private int getComponentState(JComponent c) {
......
......@@ -140,8 +140,7 @@ public class SynthOptionPaneUI extends BasicOptionPaneUI implements
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -127,8 +127,7 @@ public class SynthPanelUI extends BasicPanelUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -123,8 +123,7 @@ public class SynthPopupMenuUI extends BasicPopupMenuUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -138,8 +138,7 @@ public class SynthProgressBarUI extends BasicProgressBarUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -80,8 +80,7 @@ public class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -185,8 +185,7 @@ public class SynthScrollBarUI extends BasicScrollBarUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private SynthContext getContext(JComponent c, Region region) {
......@@ -199,8 +198,7 @@ public class SynthScrollBarUI extends BasicScrollBarUI
if (region == Region.SCROLL_BAR_THUMB) {
style = thumbStyle;
}
return SynthContext.getContext(SynthContext.class, c, region, style,
state);
return SynthContext.getContext(c, region, style, state);
}
private int getComponentState(JComponent c, Region region) {
......
......@@ -211,8 +211,7 @@ public class SynthScrollPaneUI extends BasicScrollPaneUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -248,8 +248,7 @@ public class SynthSeparatorUI extends SeparatorUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
public void propertyChange(PropertyChangeEvent evt) {
......
......@@ -722,8 +722,7 @@ public class SynthSliderUI extends BasicSliderUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private SynthContext getContext(JComponent c, Region subregion) {
......@@ -732,14 +731,13 @@ public class SynthSliderUI extends BasicSliderUI
private SynthContext getContext(JComponent c, Region subregion, int state) {
SynthStyle style = null;
Class klass = SynthContext.class;
if (subregion == Region.SLIDER_TRACK) {
style = sliderTrackStyle;
} else if (subregion == Region.SLIDER_THUMB) {
style = sliderThumbStyle;
}
return SynthContext.getContext(klass, c, subregion, style, state);
return SynthContext.getContext(c, subregion, style, state);
}
private int getComponentState(JComponent c, Region region) {
......
......@@ -278,8 +278,7 @@ public class SynthSpinnerUI extends BasicSpinnerUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
/**
......
......@@ -209,8 +209,7 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
SynthContext getContext(JComponent c, Region region) {
......@@ -219,11 +218,9 @@ public class SynthSplitPaneUI extends BasicSplitPaneUI
private SynthContext getContext(JComponent c, Region region, int state) {
if (region == Region.SPLIT_PANE_DIVIDER) {
return SynthContext.getContext(SynthContext.class, c, region,
dividerStyle, state);
return SynthContext.getContext(c, region, dividerStyle, state);
}
return SynthContext.getContext(SynthContext.class, c, region,
style, state);
return SynthContext.getContext(c, region, style, state);
}
private int getComponentState(JComponent c, Region subregion) {
......
......@@ -235,13 +235,11 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c),style, state);
return SynthContext.getContext(c, style, state);
}
private SynthContext getContext(JComponent c, Region subregion, int state){
SynthStyle style = null;
Class klass = SynthContext.class;
if (subregion == Region.TABBED_PANE_TAB) {
style = tabStyle;
......@@ -252,7 +250,7 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI
else if (subregion == Region.TABBED_PANE_CONTENT) {
style = tabContentStyle;
}
return SynthContext.getContext(klass, c, subregion, style, state);
return SynthContext.getContext(c, subregion, style, state);
}
/**
......
......@@ -193,8 +193,7 @@ public class SynthTableHeaderUI extends BasicTableHeaderUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
/**
......
......@@ -246,8 +246,7 @@ public class SynthTableUI extends BasicTableUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
//
......
......@@ -118,8 +118,7 @@ public class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI {
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
/**
......
......@@ -156,8 +156,7 @@ public class SynthTextFieldUI extends BasicTextFieldUI implements SynthUI {
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
/**
......
......@@ -178,19 +178,17 @@ public class SynthToolBarUI extends BasicToolBarUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private SynthContext getContext(JComponent c, Region region, SynthStyle style) {
return SynthContext.getContext(SynthContext.class, c, region,
return SynthContext.getContext(c, region,
style, getComponentState(c, region));
}
private SynthContext getContext(JComponent c, Region region,
SynthStyle style, int state) {
return SynthContext.getContext(SynthContext.class, c, region,
style, state);
return SynthContext.getContext(c, region, style, state);
}
private int getComponentState(JComponent c, Region region) {
......
......@@ -107,8 +107,7 @@ public class SynthToolTipUI extends BasicToolTipUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private int getComponentState(JComponent c) {
......
......@@ -173,8 +173,7 @@ public class SynthTreeUI extends BasicTreeUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private SynthContext getContext(JComponent c, Region region) {
......@@ -182,8 +181,7 @@ public class SynthTreeUI extends BasicTreeUI
}
private SynthContext getContext(JComponent c, Region region, int state) {
return SynthContext.getContext(SynthContext.class, c,
region, cellStyle, state);
return SynthContext.getContext(c, region, cellStyle, state);
}
private int getComponentState(JComponent c, Region region) {
......
......@@ -141,8 +141,7 @@ public class SynthViewportUI extends ViewportUI
}
private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c,
getRegion(c), style, state);
return SynthContext.getContext(c, style, state);
}
private Region getRegion(JComponent c) {
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.swing.JButton;
import javax.swing.plaf.synth.SynthButtonUI;
/*
* @test
* @bug 8043627
* @summary Tests that SynthContext can be created with SecurityManager installed
* @author Sergey Malenkov
*/
public class Test8043627 {
public static void main(String[] args) {
System.setSecurityManager(new SecurityManager());
new SynthButtonUI().getContext(new JButton());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册