Skip to content
Permalink
Browse files
8274505: Too weak variable type leads to unnecessary cast in java.des…
…ktop

Reviewed-by: serb, kizune, pbansal
  • Loading branch information
turbanoff authored and mrserb committed Oct 2, 2021
1 parent 0786d8b commit 9ca6bf0d22ac39d4ee29c756903038f09087ca12
Showing 11 changed files with 56 additions and 78 deletions.
@@ -289,12 +289,11 @@ private boolean loadInstruments(List<ModelInstrument> instruments) {
c.current_instrument = null;
c.current_director = null;
}
for (Instrument instrument : instruments) {
for (ModelInstrument instrument : instruments) {
String pat = patchToString(instrument.getPatch());
SoftInstrument softins
= new SoftInstrument((ModelInstrument) instrument);
SoftInstrument softins = new SoftInstrument(instrument);
inslist.put(pat, softins);
loadedlist.put(pat, (ModelInstrument) instrument);
loadedlist.put(pat, instrument);
}
}

@@ -868,11 +868,11 @@ private AbstractFormatterFactory getDefaultFormatterFactory(Object type) {
return new DefaultFormatterFactory(new DateFormatter());
}
if (type instanceof Number) {
AbstractFormatter displayFormatter = new NumberFormatter();
((NumberFormatter)displayFormatter).setValueClass(type.getClass());
AbstractFormatter editFormatter = new NumberFormatter(
NumberFormatter displayFormatter = new NumberFormatter();
displayFormatter.setValueClass(type.getClass());
NumberFormatter editFormatter = new NumberFormatter(
new DecimalFormat("#.#"));
((NumberFormatter)editFormatter).setValueClass(type.getClass());
editFormatter.setValueClass(type.getClass());

return new DefaultFormatterFactory(displayFormatter,
displayFormatter,editFormatter);
@@ -24,18 +24,13 @@
*/
package javax.swing;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.security.AccessController;
import javax.accessibility.*;
import javax.swing.plaf.RootPaneUI;
import java.util.Vector;
import java.io.Serializable;
import javax.swing.border.*;

import sun.awt.AWTAccessor;
import sun.security.action.GetBooleanAction;


@@ -511,10 +506,10 @@ public void addLayoutComponent(Component comp, Object constraints) {
* @return the default <code>glassPane</code>
*/
protected Component createGlassPane() {
JComponent c = new JPanel();
JPanel c = new JPanel();
c.setName(this.getName()+".glassPane");
c.setVisible(false);
((JPanel)c).setOpaque(false);
c.setOpaque(false);
return c;
}

@@ -2033,7 +2033,7 @@ public Enumeration<TreePath> getExpandedDescendants(TreePath parent) {
Enumeration<TreePath> toggledPaths = expandedState.keys();
Vector<TreePath> elements = null;
TreePath path;
Object value;
Boolean value;

if(toggledPaths != null) {
while(toggledPaths.hasMoreElements()) {
@@ -2042,8 +2042,7 @@ public Enumeration<TreePath> getExpandedDescendants(TreePath parent) {
// Add the path if it is expanded, a descendant of parent,
// and it is visible (all parents expanded). This is rather
// expensive!
if(path != parent && value != null &&
((Boolean)value).booleanValue() &&
if (path != parent && value != null && value &&
parent.isDescendant(path) && isVisible(path)) {
if (elements == null) {
elements = new Vector<TreePath>();
@@ -2081,11 +2080,11 @@ public boolean isExpanded(TreePath path) {

if(path == null)
return false;
Object value;
Boolean value;

do{
value = expandedState.get(path);
if(value == null || !((Boolean)value).booleanValue())
if (value == null || !value)
return false;
} while( (path=path.getParentPath())!=null );

@@ -2109,7 +2108,7 @@ public boolean isExpanded(int row) {
if(path != null) {
Boolean value = expandedState.get(path);

return (value != null && value.booleanValue());
return (value != null && value);
}
}
return false;
@@ -3729,9 +3728,9 @@ protected void setExpandedState(TreePath path, boolean state) {
}
if(!state) {
// collapse last path.
Object cValue = expandedState.get(path);
Boolean cValue = expandedState.get(path);

if(cValue != null && ((Boolean)cValue).booleanValue()) {
if (cValue != null && cValue) {
try {
fireTreeWillCollapse(path);
}
@@ -3753,9 +3752,9 @@ protected void setExpandedState(TreePath path, boolean state) {
}
else {
// Expand last path.
Object cValue = expandedState.get(path);
Boolean cValue = expandedState.get(path);

if(cValue == null || !((Boolean)cValue).booleanValue()) {
if (cValue == null || !cValue) {
try {
fireTreeWillExpand(path);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, 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
@@ -1024,10 +1024,7 @@ private void addPainterOrMerge(List<ParsedSynthStyle.PainterInfo> painters, Stri
painter,
direction);

for (Object infoObject: painters) {
ParsedSynthStyle.PainterInfo info;
info = (ParsedSynthStyle.PainterInfo) infoObject;

for (ParsedSynthStyle.PainterInfo info: painters) {
if (painterInfo.equalsPainter(info)) {
info.addPainter(painter);
return;
@@ -317,14 +317,12 @@ public AccessibleContext getAccessibleContext() {
*/
public AccessibleStateSet getAccessibleStateSet() {
AccessibleStateSet states = new AccessibleStateSet();
Component comp = getTextComponent();
JTextComponent comp = getTextComponent();

if (comp.isEnabled()) {
states.add(AccessibleState.ENABLED);
}
if (comp instanceof JTextComponent &&
((JTextComponent)comp).isEditable()) {

if (comp.isEditable()) {
states.add(AccessibleState.EDITABLE);
states.add(AccessibleState.FOCUSABLE);
}
@@ -742,11 +740,9 @@ private ElementInfo getElementInfoAt(ElementInfo elementInfo, Point p) {
* @see AccessibleStateSet
*/
public boolean isFocusTraversable() {
Component comp = getTextComponent();
if (comp instanceof JTextComponent) {
if (((JTextComponent)comp).isEditable()) {
return true;
}
JTextComponent comp = getTextComponent();
if (comp != null && comp.isEditable()) {
return true;
}
return false;
}
@@ -763,16 +759,16 @@ public void requestFocus() {
return;
}

Component comp = getTextComponent();
if (comp instanceof JTextComponent) {
JTextComponent comp = getTextComponent();
if (comp != null) {

comp.requestFocusInWindow();

try {
if (elementInfo.validateIfNecessary()) {
// set the caret position to the start of this component
Element elem = elementInfo.getElement();
((JTextComponent)comp).setCaretPosition(elem.getStartOffset());
comp.setCaretPosition(elem.getStartOffset());

// fire a AccessibleState.FOCUSED property change event
AccessibleContext ac = editor.getAccessibleContext();
@@ -4195,7 +4195,7 @@ private void foundInsertTag(boolean isBlockTag) {
try {
if (offset == 0 || !getText(offset - 1, 1).equals("\n")) {
// Need to insert a newline.
AttributeSet newAttrs = null;
SimpleAttributeSet newAttrs = null;
boolean joinP = true;

if (offset != 0) {
@@ -4229,9 +4229,8 @@ private void foundInsertTag(boolean isBlockTag) {
// sure and set the name (otherwise it will be
// inherited).
newAttrs = new SimpleAttributeSet();
((SimpleAttributeSet)newAttrs).addAttribute
(StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
newAttrs.addAttribute(StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
}
ElementSpec es = new ElementSpec(newAttrs,
ElementSpec.ContentType, NEWLINE, 0,
@@ -61,7 +61,6 @@
import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleContext;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JViewport;
import javax.swing.SizeRequirements;
@@ -848,13 +847,12 @@ private String getMapHREF(JEditorPane html, HTMLDocument hdoc,
Rectangle bounds;
TextUI ui = html.getUI();
try {
Shape lBounds = ui.modelToView(html, offset,
Rectangle lBounds = ui.modelToView(html, offset,
Position.Bias.Forward);
Shape rBounds = ui.modelToView(html, offset + 1,
Rectangle rBounds = ui.modelToView(html, offset + 1,
Position.Bias.Backward);
bounds = lBounds.getBounds();
bounds.add((rBounds instanceof Rectangle) ?
(Rectangle)rBounds : rBounds.getBounds());
bounds = lBounds;
bounds.add(rBounds);
} catch (BadLocationException ble) {
bounds = null;
}
@@ -885,18 +883,14 @@ private boolean doesElementContainLocation(JEditorPane editor,
if (e != null && offset > 0 && e.getStartOffset() == offset) {
try {
TextUI ui = editor.getUI();
Shape s1 = ui.modelToView(editor, offset,
Position.Bias.Forward);
if (s1 == null) {
Rectangle r1 = ui.modelToView(editor, offset,
Position.Bias.Forward);
if (r1 == null) {
return false;
}
Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle)s1 :
s1.getBounds();
Shape s2 = ui.modelToView(editor, e.getEndOffset(),
Position.Bias.Backward);
if (s2 != null) {
Rectangle r2 = (s2 instanceof Rectangle) ? (Rectangle)s2 :
s2.getBounds();
Rectangle r2 = ui.modelToView(editor, e.getEndOffset(),
Position.Bias.Backward);
if (r2 != null) {
r1.add(r2);
}
return r1.contains(x, y);
@@ -1517,9 +1511,9 @@ public void setParent(View parent) {
//if parent == null unregister component listener
if (parent == null) {
if (cachedViewPort != null) {
Object cachedObject;
JViewport cachedObject;
if ((cachedObject = cachedViewPort.get()) != null) {
((JComponent)cachedObject).removeComponentListener(this);
cachedObject.removeComponentListener(this);
}
cachedViewPort = null;
}
@@ -27,7 +27,6 @@
import java.lang.*;
import java.util.*;
import java.awt.Color;
import java.awt.Font;
import java.io.OutputStream;
import java.io.IOException;

@@ -515,13 +514,13 @@ void updateSectionAttributes(MutableAttributeSet current,
{
if (emitStyleChanges) {
Object oldStyle = current.getAttribute("sectionStyle");
Object newStyle = findStyleNumber(newAttributes, Constants.STSection);
Integer newStyle = findStyleNumber(newAttributes, Constants.STSection);
if (oldStyle != newStyle) {
if (oldStyle != null) {
resetSectionAttributes(current);
}
if (newStyle != null) {
writeControlWord("ds", ((Integer)newStyle).intValue());
writeControlWord("ds", newStyle);
current.addAttribute("sectionStyle", newStyle);
} else {
current.removeAttribute("sectionStyle");
@@ -554,8 +553,8 @@ void updateParagraphAttributes(MutableAttributeSet current,
boolean emitStyleChanges)
throws IOException
{
Object parm;
Object oldStyle, newStyle;
Object oldStyle;
Integer newStyle;

/* The only way to get rid of tabs or styles is with the \pard keyword,
emitted by resetParagraphAttributes(). Ideally we should avoid
@@ -587,7 +586,7 @@ emitted by resetParagraphAttributes(). Ideally we should avoid
}

if (oldStyle != newStyle && newStyle != null) {
writeControlWord("s", ((Integer)newStyle).intValue());
writeControlWord("s", newStyle);
current.addAttribute("paragraphStyle", newStyle);
}

@@ -706,14 +705,14 @@ void updateCharacterAttributes(MutableAttributeSet current,

if (updateStyleChanges) {
Object oldStyle = current.getAttribute("characterStyle");
Object newStyle = findStyleNumber(newAttributes,
Integer newStyle = findStyleNumber(newAttributes,
Constants.STCharacter);
if (oldStyle != newStyle) {
if (oldStyle != null) {
resetCharacterAttributes(current);
}
if (newStyle != null) {
writeControlWord("cs", ((Integer)newStyle).intValue());
writeControlWord("cs", newStyle.intValue());
current.addAttribute("characterStyle", newStyle);
} else {
current.removeAttribute("characterStyle");
@@ -1803,8 +1803,8 @@ public static RenderingHints getDesktopFontHints() {
if (useSystemAAFontSettings()) {
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
Object map = ((SunToolkit)tk).getDesktopAAHints();
return (RenderingHints)map;
RenderingHints map = ((SunToolkit)tk).getDesktopAAHints();
return map;
} else { /* Headless Toolkit */
return null;
}
@@ -142,8 +142,8 @@ synchronized void add(Object target, DisposerRecord rec) {
public void run() {
while (true) {
try {
Object obj = queue.remove();
((Reference)obj).clear();
Reference<?> obj = queue.remove();
obj.clear();
DisposerRecord rec = records.remove(obj);
rec.dispose();
obj = null;
@@ -200,15 +200,15 @@ public static void pollRemove() {
if (pollingQueue) {
return;
}
Object obj;
Reference<?> obj;
pollingQueue = true;
int freed = 0;
int deferred = 0;
try {
while ( freed < 10000 && deferred < 100 &&
(obj = queue.poll()) != null ) {
freed++;
((Reference)obj).clear();
obj.clear();
DisposerRecord rec = records.remove(obj);
if (rec instanceof PollDisposable) {
rec.dispose();

1 comment on commit 9ca6bf0

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 9ca6bf0 Oct 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.