Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testCommandDescriptor() throws IOException {
desc.getProps().setProperty("wrong", "wrong");
assertEquals(props, desc.getProps());

String[] correctArgs = args.clone();
String[] correctArgs = new ArrayList<String>.toArray(args);
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't compile since the () is missing. But what worse is that this is wrong. It would create an empty AL and copy null into the first element of args to mark the end of the (empty) array.

please use Arrays.copyOf(args, args.length) for example. Same applies to the other occurrences.

args[0] = "wrong";
assertEquals(correctArgs, desc.getArguments());
Properties correctProps = new Properties(props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void propertyChange(PropertyChangeEvent pce) {
}

public Node[] getSelectedNodes(){
return selectedNodes.clone();
return (new ArrayList<Node>()).toArray(selectedNodes);
}

public ExplorerManager getExplorerManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

Expand Down Expand Up @@ -260,18 +261,18 @@ public DriverSpecification createDriverSpecification(String driverName) {
/** Creates deep copy of Map.
* All items will be cloned. Used internally in this object.
*/
private HashMap deepClone(HashMap map) {
HashMap newone = (HashMap)map.clone();
private Map<Object, Object> deepClone(Map map) {
Map<Object, Object> newone = new HashMap<>(map);
Iterator it = newone.keySet().iterator();
while (it.hasNext()) {
Object newkey = it.next();
Object deepobj = null, newobj = newone.get(newkey);
if (newobj instanceof HashMap)
deepobj = deepClone((HashMap)newobj);
else if (newobj instanceof String)
deepobj = (Object)new String((String)newobj);
deepobj = new String((String)newobj);
else if (newobj instanceof Vector)
deepobj = ((Vector)newobj).clone();
deepobj = new Vector((Vector)newobj);
newone.put(newkey, deepobj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public synchronized Collection<Node> getNodes() {

public synchronized void refresh() {
initialized = false;
@SuppressWarnings("unchecked")
TreeSet<Node> nodes = (TreeSet<Node>)nodeSet.clone();
Set<Node> nodes = new TreeSet<>(nodeSet);

for (Node child : nodes) {
if (child instanceof BaseNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public void setDisplayName(String value) {

@Override
public Properties getConnectionProperties() {
return (Properties) connectionProperties.clone();
return new Properties(connectionProperties);
}

@Override
Expand All @@ -589,7 +589,7 @@ public void setConnectionProperties(Properties connectionProperties) {
if (connectionProperties == null) {
this.connectionProperties = new Properties();
} else {
this.connectionProperties = (Properties) connectionProperties.clone();
this.connectionProperties = new Properties(connectionProperties);
}
propertySupport.firePropertyChange(PROP_CONNECTIONPROPERTIES, old, connectionProperties);
}
Expand Down
2 changes: 1 addition & 1 deletion ide/editor.lib/src/org/netbeans/editor/PopupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ protected static Rectangle computeBounds(JComponent popup,
if (viewParent instanceof JViewport) {
Rectangle viewBounds = ((JViewport)viewParent).getViewRect();

Rectangle translatedCursorBounds = (Rectangle)cursorBounds.clone();
Rectangle translatedCursorBounds = new Rectangle(cursorBounds);
if (placement != FixedPoint) {
translatedCursorBounds.translate(-viewBounds.x, -viewBounds.y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,10 @@ public Set<LanguagePath> languagePaths() {
return Collections.emptySet();
Language<?> lang = rootTokenList.language();
LanguageOperation<?> langOp = LexerApiPackageAccessor.get().languageOperation(lang);
@SuppressWarnings("unchecked")
Set<LanguagePath> clps = (Set<LanguagePath>)
((HashSet<LanguagePath>)langOp.languagePaths()).clone();
Set<LanguagePath> clps = new HashSet<>(langOp.languagePaths());
lps = clps;

@SuppressWarnings("unchecked")
Set<Language<?>> cel = (Set<Language<?>>)
((HashSet<Language<?>>)langOp.exploredLanguages()).clone();
Set<Language<?>> cel = new HashSet<>(langOp.exploredLanguages());
exploredLanguages = cel;
languagePaths = lps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ public Object clone() {
}

if (attrCache != null)
bean.attrCache = (HashMap) attrCache.clone(); // This does a shallow clone of the HashMap, but that's fine since they're all just Strings in there.
bean.attrCache = new HashMap<>(attrCache); // This does a shallow clone of the HashMap, but that's fine since they're all just Strings in there.

Iterator it = beanPropsIterator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@
*/
public class ListenersSupport {

private final Object source;
private HashSet listeners = new HashSet(1);
private final Object source;
private Set<VersioningListener> listeners = new HashSet<>(1);

public ListenersSupport(Object source) {
this.source = source;
}

public synchronized void addListener(VersioningListener listener) {
if (listener == null) throw new IllegalArgumentException();
HashSet copy = (HashSet) listeners.clone();
Set<VersioningListener> copy = new HashSet<>(listeners);
copy.add(listener);
listeners = copy;
}

public synchronized void removeListener(VersioningListener listener) {
HashSet copy = (HashSet) listeners.clone();
Set<VersioningListener> copy = new HashSet<>(listeners);
copy.remove(listener);
listeners = copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public final ClassName getType() {
* array of AnnotationComponents.
*/
public final AnnotationComponent[] getComponents() {
return components.clone();
return new ArrayList<AnnotationComponent>().toArray(components);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package org.netbeans.modules.classfile;

import java.util.ArrayList;

/**
* ArrayElementValue: the value portion of an annotation element that
* is an array of ElementValue instances.
Expand All @@ -39,7 +41,7 @@ public final class ArrayElementValue extends ElementValue {
* Returns the set of ElementValue instances for this component.
*/
public ElementValue[] getValues() {
return values.clone();
return new ArrayList<ElementValue>().toArray(values);
}

@Override
Expand Down
9 changes: 5 additions & 4 deletions java/classfile/src/org/netbeans/modules/classfile/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;

/**
* The Code attribute of a method.
Expand Down Expand Up @@ -127,7 +128,7 @@ public final byte[] getByteCodes() {
}

public final ExceptionTableEntry[] getExceptionTable() {
return exceptionTable.clone();
return new ArrayList<ExceptionTableEntry>().toArray(exceptionTable);
}

/**
Expand All @@ -143,7 +144,7 @@ public final int[] getLineNumberTable() {
* Returns the local variable table for this code.
*/
public final LocalVariableTableEntry[] getLocalVariableTable() {
return localVariableTable.clone();
return new ArrayList<LocalVariableTableEntry>().toArray(localVariableTable);
}

/**
Expand All @@ -152,15 +153,15 @@ public final LocalVariableTableEntry[] getLocalVariableTable() {
* are generic.
*/
public final LocalVariableTypeTableEntry[] getLocalVariableTypeTable() {
return localVariableTypeTable.clone();
return new ArrayList<LocalVariableTypeTableEntry>().toArray(localVariableTypeTable);
}

/**
* Returns the stack map table for this code, which defines the stack frame
* information needed by the new classfile verifier in Java 6.
*/
public final StackMapFrame[] getStackMapTable() {
return stackMapTable.clone();
return new ArrayList<StackMapFrame>().toArray(stackMapTable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;

/**
* A Java method object.
Expand Down Expand Up @@ -96,7 +97,7 @@ public final CPClassInfo[] getExceptionClasses() {
if (exceptions == null)
exceptions = new CPClassInfo[0];
}
return exceptions.clone();
return new ArrayList<CPClassInfo>().toArray(exceptions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;

/**
* A stack map frame, as defined by a StackMapTable attribute. A stack map
Expand Down Expand Up @@ -270,7 +271,7 @@ public int getOffsetDelta() {
* locals.
*/
public VerificationTypeInfo[] getLocals() {
return locals.clone();
return new ArrayList<VerificationTypeInfo>().toArray(locals);
}
}

Expand Down Expand Up @@ -302,15 +303,15 @@ public int getOffsetDelta() {
* locals.
*/
public VerificationTypeInfo[] getLocals() {
return locals.clone();
return new ArrayList<VerificationTypeInfo>().toArray(locals);
}

/**
* Returns the verification type info for this frame's set of
* stack items.
*/
public VerificationTypeInfo[] getStackItems() {
return stackItems.clone();
return new ArrayList<VerificationTypeInfo>().toArray(stackItems);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.netbeans.modules.dbschema.jdbcimpl.wizard;

import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.swing.*;
Expand Down Expand Up @@ -168,10 +169,10 @@ public void initData() {
}

public void fireChange (Object source) {
ArrayList lst;
List<ChangeListener> lst;

synchronized (this) {
lst = (ArrayList) this.list.clone();
lst = new ArrayList<>(this.list);
}

ChangeEvent event = new ChangeEvent(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,10 @@ public void contentsChanged(javax.swing.event.ListDataEvent p1) {
}

public void fireChange (Object source) {
ArrayList lst;
List<ChangeListener> lst;

synchronized (this) {
lst = (ArrayList) this.list.clone();
lst = new ArrayList<>(this.list);
}

ChangeEvent event = new ChangeEvent(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,6 @@ public Path getPlainPath() {
pp.setLocation(getLocation());
pp.setDescription(getDescription());
pp.setRefid(getRefid());
//pp.setChecked(isChecked());
//pp.union = union == null ? union : (Union) union.clone();
plainPath = pp;
} else {
plainPath = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public void removeModelListener (ModelListener l) {
}

public void fireTreeChanged () {
Vector v = (Vector) listeners.clone ();
Vector<ModelListener> v = new Vector<>(listeners);
int i, k = v.size ();
for (i = 0; i < k; i++) {
((ModelListener) v.get (i)).modelChanged (null);
Expand All @@ -397,7 +397,7 @@ public void fireTreeChanged () {

private void fireSelectedNodes(Object[] nodes) {
ModelEvent event = new ModelEvent.SelectionChanged(this, nodes);
Vector v = (Vector) listeners.clone ();
Vector<ModelListener> v = new Vector<>(listeners);
int i, k = v.size ();
for (i = 0; i < k; i++) {
((ModelListener) v.get (i)).modelChanged (event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void removeModelListener (ModelListener l) {
}

public void fireTreeChanged () {
Vector v = (Vector) listeners.clone ();
Vector<ModelListener> v = new Vector<>(listeners);
int i, k = v.size ();
for (i = 0; i < k; i++) {
((ModelListener) v.get (i)).modelChanged (null);
Expand All @@ -238,7 +238,7 @@ public void fireTreeChanged () {

private void fireSelectedNodes(Object[] nodes) {
ModelEvent event = new ModelEvent.SelectionChanged(this, nodes);
Vector v = (Vector) listeners.clone ();
Vector<ModelListener> v = new Vector<>(listeners);
int i, k = v.size ();
for (i = 0; i < k; i++) {
((ModelListener) v.get (i)).modelChanged (event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public void removeModelListener (ModelListener l) {
//

private void fireNodeChanged (JPDABreakpoint b) {
Vector v = (Vector) listeners.clone ();
Vector<ModelListener> v = new Vector<>(listeners);
int i, k = v.size ();
for (i = 0; i < k; i++)
((ModelListener) v.get (i)).modelChanged (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ public void actionPerformed(ActionEvent e) {
}

public void addModelListener(ModelListener l) {
HashSet newListeners = (listeners == null) ? new HashSet() : (HashSet) listeners.clone();
HashSet newListeners = (listeners == null) ? new HashSet() : new HashSet<>(listeners);
newListeners.add(l);
listeners = newListeners;
}

public void removeModelListener(ModelListener l) {
if (listeners == null) return;
HashSet newListeners = (HashSet) listeners.clone();
HashSet newListeners = new HashSet<>(listeners);
newListeners.remove(l);
listeners = newListeners;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ public void setValueAt (

public void addModelListener (ModelListener l) {
HashSet newListeners = (listeners == null) ?
new HashSet () : (HashSet) listeners.clone ();
new HashSet () : new HashSet<>(listeners);
newListeners.add (l);
listeners = newListeners;
}

public void removeModelListener (ModelListener l) {
if (listeners == null) return;
HashSet newListeners = (HashSet) listeners.clone();
HashSet newListeners = new HashSet<>(listeners);
newListeners.remove (l);
listeners = newListeners;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void removeModelListener (ModelListener l) {
}

private void fireTreeChanged () {
Vector v = (Vector) listeners.clone ();
Vector<ModelListener> v = new Vector<>(listeners);
int i, k = v.size ();
for (i = 0; i < k; i++)
((ModelListener) v.get (i)).modelChanged (null);
Expand Down
Loading