Skip to content
Merged
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
28 changes: 14 additions & 14 deletions CodenameOne/src/com/codename1/charts/models/XYSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void setTitle(String title) {
* @param x the value for the X axis
* @param y the value for the Y axis
*/
public synchronized void add(double x, double y) {
public void add(double x, double y) {
while (mXY.get(x) != null) {
// add a very small value to x such as data points sharing the same x will
// still be added
Comment on lines +151 to 154

Choose a reason for hiding this comment

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

P1 Badge Restore synchronization on XYSeries mutations

The XYSeries mutators were unsynchronized in this change, but they still mutate and iterate over the shared TreeMap/ArrayList backing (mXY and the index list). When chart data is updated from a background thread while the UI thread renders (getRange, getX/Y, etc.), concurrent access to these non-thread-safe structures can now throw ConcurrentModificationException or corrupt min/max tracking; the previous synchronization prevented that race.

Useful? React with 👍 / 👎.

Expand All @@ -165,7 +165,7 @@ public synchronized void add(double x, double y) {
* @param x the value for the X axis
* @param y the value for the Y axis
*/
public synchronized void add(int index, double x, double y) {
public void add(int index, double x, double y) {
while (mXY.get(x) != null) {
// add a very small value to x such as data points sharing the same x will
// still be added
Expand All @@ -184,7 +184,7 @@ protected double getPadding(double x) {
*
* @param index the index in the series of the value to remove
*/
public synchronized void remove(int index) {
public void remove(int index) {
XYEntry<Double, Double> removedEntry = mXY.removeByIndex(index);
double removedX = removedEntry.getKey();
double removedY = removedEntry.getValue();
Expand All @@ -196,33 +196,33 @@ public synchronized void remove(int index) {
/**
* Removes all the existing values and annotations from the series.
*/
public synchronized void clear() {
public void clear() {
clearAnnotations();
clearSeriesValues();
}

/**
* Removes all the existing values from the series but annotations.
*/
public synchronized void clearSeriesValues() {
public void clearSeriesValues() {
mXY.clear();
initRange();
}

/**
* Removes all the existing annotations from the series.
*/
public synchronized void clearAnnotations() {
mStringXY.clear();
mAnnotations.clear();
}
public void clearAnnotations() {
mStringXY.clear();
mAnnotations.clear();
}

/**
* Returns the current values that are used for drawing the series.
*
* @return the XY map
*/
public synchronized IndexXYMap<Double, Double> getXYMap() {
public IndexXYMap<Double, Double> getXYMap() {
return mXY;
}

Expand All @@ -232,7 +232,7 @@ public synchronized IndexXYMap<Double, Double> getXYMap() {
* @param index the index
* @return the X value
*/
public synchronized double getX(int index) {
public double getX(int index) {
return mXY.getXByIndex(index);
}

Expand All @@ -242,7 +242,7 @@ public synchronized double getX(int index) {
* @param index the index
* @return the Y value
*/
public synchronized double getY(int index) {
public double getY(int index) {
return mXY.getYByIndex(index);
}

Expand Down Expand Up @@ -335,7 +335,7 @@ public String getAnnotationAt(int index) {
* visible ones must be displayed
* @return a submap of x and y values
*/
public synchronized SortedMap<Double, Double> getRange(double start, double stop,
public SortedMap<Double, Double> getRange(double start, double stop,
boolean beforeAfterPoints) {
if (beforeAfterPoints) {
// we need to add one point before the start and one point after the end
Expand Down Expand Up @@ -379,7 +379,7 @@ public int getIndexForKey(double key) {
*
* @return the series item count
*/
public synchronized int getItemCount() {
public int getItemCount() {
return mXY.size();
}

Expand Down
10 changes: 5 additions & 5 deletions CodenameOne/src/com/codename1/charts/models/XYValueSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public XYValueSeries(String title) {
* @param y the value for the Y axis
* @param value the value
*/
public synchronized void add(double x, double y, double value) {
public void add(double x, double y, double value) {
super.add(x, y);
mValue.add(value);
updateRange(value);
Expand Down Expand Up @@ -82,7 +82,7 @@ private void updateRange(double value) {
* @param x the value for the X axis
* @param y the value for the Y axis
*/
public synchronized void add(double x, double y) {
public void add(double x, double y) {
add(x, y, 0d);
}

Expand All @@ -91,7 +91,7 @@ public synchronized void add(double x, double y) {
*
* @param index the index in the series of the value to remove
*/
public synchronized void remove(int index) {
public void remove(int index) {
super.remove(index);
double removedValue = mValue.remove(index);
if (removedValue == mMinValue || removedValue == mMaxValue) {
Expand All @@ -102,7 +102,7 @@ public synchronized void remove(int index) {
/**
* Removes all the values from the series.
*/
public synchronized void clear() {
public void clear() {
super.clear();
mValue.clear();
initRange();
Expand All @@ -114,7 +114,7 @@ public synchronized void clear() {
* @param index the index
* @return the value
*/
public synchronized double getValue(int index) {
public double getValue(int index) {
return mValue.get(index);
}

Expand Down
32 changes: 16 additions & 16 deletions CodenameOne/src/com/codename1/io/BufferedInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public class BufferedInputStream extends InputStream {
private static int streamCount = 0;
private static int defaultBufferSize = 8192;
private static volatile int defaultBufferSize = 8192;
private int actualAvailable = defaultBufferSize;
private Object connection;
private InputStream in;
Expand Down Expand Up @@ -212,10 +212,10 @@ public String getName() {
}

/**
* Check to make sure that underlying input stream has not been
* Check to make sure that the underlying input stream has not been
* nulled out due to close; if not return it;
*/
private InputStream getInIfOpen() throws IOException {
private synchronized InputStream getInIfOpen() throws IOException {
InputStream input = in;
if (input == null) {
throw new IOException("Stream closed");
Expand All @@ -227,7 +227,7 @@ private InputStream getInIfOpen() throws IOException {
* Check to make sure that buffer has not been nulled out due to
* close; if not return it;
*/
private byte[] getBufIfOpen() throws IOException {
private synchronized byte[] getBufIfOpen() throws IOException {
byte[] buffer = buf;
if (buffer == null) {
throw new IOException("Stream closed");
Expand Down Expand Up @@ -377,7 +377,7 @@ private int read1(byte[] b, int off, int len) throws IOException {
return cnt;
}

private void yieldTime() {
private synchronized void yieldTime() {
long time = System.currentTimeMillis();
if (time - elapsedSinceLastYield > 300) {
try {
Expand Down Expand Up @@ -656,16 +656,16 @@ public void close() throws IOException {
*
* @return time of the last activity on this stream
*/
public long getLastActivityTime() {
public synchronized long getLastActivityTime() {
return lastActivityTime;
}

/**
* Returns the total amount of bytes read from this stream so far
* Returns the total number of bytes read from this stream so far
*
* @return the total amount of bytes read from this stream so far
* @return the total number of bytes read from this stream so far
*/
public int getTotalBytesRead() {
public synchronized int getTotalBytesRead() {
return totalBytesRead;
}

Expand Down Expand Up @@ -706,14 +706,14 @@ public void setConnection(Object connection) {
/**
* @return the disableBuffering
*/
public boolean isDisableBuffering() {
public synchronized boolean isDisableBuffering() {
return disableBuffering;
}

/**
* @param disableBuffering the disableBuffering to set
*/
public void setDisableBuffering(boolean disableBuffering) {
public synchronized void setDisableBuffering(boolean disableBuffering) {
this.disableBuffering = disableBuffering;
}

Expand All @@ -723,7 +723,7 @@ public void setDisableBuffering(boolean disableBuffering) {
*
* @return the printInput
*/
public boolean isPrintInput() {
public synchronized boolean isPrintInput() {
return printInput;
}

Expand All @@ -733,7 +733,7 @@ public boolean isPrintInput() {
*
* @param printInput the printInput to set
*/
public void setPrintInput(boolean printInput) {
public synchronized void setPrintInput(boolean printInput) {
this.printInput = printInput;
}

Expand All @@ -743,7 +743,7 @@ public void setPrintInput(boolean printInput) {
*
* @return the yield
*/
public int getYield() {
public synchronized int getYield() {
return yield;
}

Expand All @@ -753,15 +753,15 @@ public int getYield() {
*
* @param yield the yield to set
*/
public void setYield(int yield) {
public synchronized void setYield(int yield) {
this.yield = yield;
}

/**
* Stop reading from the stream, invoking this will cause the read() to
* return -1
*/
public void stop() {
public synchronized void stop() {
stopped = true;
}

Expand Down
6 changes: 3 additions & 3 deletions CodenameOne/src/com/codename1/io/BufferedOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public String getName() {
/**
* Flush the internal buffer
*/
public void flushBuffer() throws IOException {
public synchronized void flushBuffer() throws IOException {
if (closed) {
return;
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public synchronized void flush() throws IOException {
*
* @return time of the last activity on this stream
*/
public long getLastActivityTime() {
public synchronized long getLastActivityTime() {
return lastActivityTime;
}

Expand All @@ -227,7 +227,7 @@ public long getLastActivityTime() {
*
* @return the total amount of bytes written to this stream so far
*/
public int getTotalBytesWritten() {
public synchronized int getTotalBytesWritten() {
return totalBytesWritten;
}

Expand Down
6 changes: 4 additions & 2 deletions CodenameOne/src/com/codename1/l10n/DateFormatSymbols.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ public void setAmPmStrings(String[] newAmpms) {
ampms = newAmpms;
}

public Hashtable<String, String> getResourceBundle() {
public synchronized Hashtable<String, String> getResourceBundle() {
return resourceBundle;
}

public void setResourceBundle(Hashtable<String, String> newResourceBundle) {
this.resourceBundle = newResourceBundle;
synchronized (this) {
this.resourceBundle = newResourceBundle;
}
// force rebuild
ampms = null;
months = null;
Expand Down
10 changes: 5 additions & 5 deletions CodenameOne/src/com/codename1/ui/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -2919,7 +2919,7 @@ public void setVirtualKeyboardListener(ActionListener l) {
* @see #removeVirtualKeyboardListener(com.codename1.ui.events.ActionListener)
* @since 6.0
*/
public synchronized void addVirtualKeyboardListener(ActionListener l) {
public void addVirtualKeyboardListener(ActionListener l) {
if (virtualKeyboardListeners == null) {
virtualKeyboardListeners = new EventDispatcher();
}
Expand All @@ -2937,7 +2937,7 @@ public synchronized void addVirtualKeyboardListener(ActionListener l) {
* @see #addVirtualKeyboardListener(com.codename1.ui.events.ActionListener)
* @since 6.0
*/
public synchronized void removeVirtualKeyboardListener(ActionListener l) {
public void removeVirtualKeyboardListener(ActionListener l) {
if (virtualKeyboardListeners != null) {
virtualKeyboardListeners.removeListener(l);
}
Expand Down Expand Up @@ -3422,7 +3422,7 @@ public void dispatchMessage(MessageEvent evt) {
*
* @param l the listener to add
*/
public synchronized void addWindowListener(ActionListener<WindowEvent> l) {
public void addWindowListener(ActionListener<WindowEvent> l) {
if (windowListeners == null) {
windowListeners = new EventDispatcher();
}
Expand All @@ -3434,7 +3434,7 @@ public synchronized void addWindowListener(ActionListener<WindowEvent> l) {
*
* @param l the listener to remove
*/
public synchronized void removeWindowListener(ActionListener<WindowEvent> l) {
public void removeWindowListener(ActionListener<WindowEvent> l) {
if (windowListeners != null) {
windowListeners.removeListener(l);
}
Expand Down Expand Up @@ -5222,7 +5222,7 @@ private class EdtException extends RuntimeException {
private Throwable cause;
private EdtException parent;

public synchronized Throwable getCause() {
public Throwable getCause() {
return cause;
}

Expand Down
4 changes: 2 additions & 2 deletions CodenameOne/src/com/codename1/ui/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -1576,15 +1576,15 @@ public boolean requiresDrawImage() {
}

@Override
public synchronized void addActionListener(ActionListener l) {
public void addActionListener(ActionListener l) {
if (listeners == null) {
listeners = new EventDispatcher();
}
listeners.addListener(l);
}

@Override
public synchronized void removeActionListener(ActionListener l) {
public void removeActionListener(ActionListener l) {
if (listeners != null) {
listeners.removeListener(l);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ synchronized int getCSSCount() {
*
* @return the queue size
*/
int getQueueSize() {
synchronized int getQueueSize() {
return (images.size() + queue.size()); // CSS files are added directly to queue while images to the images vector
//return queue.size();
}
Expand Down
Loading