FAQ
Cover
\
Build
\
Source
\
Bugs
\
Reference
\
Libraries
\
Tools
The bugs database has moved
here
.
Bug 136 : Use of "synchronized" causing incorrect java code generation
Last modified: 2008-05-29 15:48
P
roject:
processing
trash
Version:
unspecified
Co
m
ponent:
android
book
core
libraries
pde
reference
tools
web
Status:
RESOLVED
Resolution:
FIXED -
Pr
i
ority:
P4
Severity:
normal
Platform
All
O
S:
All
Windows
Mac OS
Linux
Other
Reporter:
vemuri
Assigned To:
fry
Attachment
Type
Created
Size
Actions
Description
: Opened: 2005-08-23 12:27
When trying to do some multi-threaded code, tried to use the synchronized(var) { } syntax
to protect use of var. Processing fails to generate the correct java code for this. For
example, below is a sample bit of Processing code:
java.util.List alist = Collections.synchronizedList(new ArrayList());
void setup() {
size(400, 200);
alist.add("hello");
}
void draw() {
rect(width/4, height/4, width/2, height/2);
synchronized(alist) {
alist.get(0);
}
}
The following errors are reported by Processing:
/tmp/build/Temporary_6995_7622.java:11:20:13:14: Syntax Error: "}" inserted to complete
MethodBody
/tmp/build/Temporary_6995_7622.java:1:268:13:14: Syntax Error: "}" inserted to complete
ClassBody
/tmp/build/Temporary_6995_7622.java:13:3:13:14: Syntax Error: "Type
VariableDeclarators" inserted to complete LocalVariableDeclaration
/tmp/build/Temporary_6995_7622.java:13:3:13:14: Syntax Error: ";" inserted to complete
LocalVariableDeclarationStatement
Now, below is the corresponding java code:
[dyn5:~] vemuri% cat /tmp/build/Temporary_6995_7622.java
import processing.core.*; import java.applet.*; import java.awt.*; import
java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import
java.text.*; import java.util.*; import java.util.zip.*; public class Temporary_6995_7622
extends PApplet {
java.util.List alist = Collections.synchronizedList(new ArrayList());
public void setup() {
size(400, 200);
alist.add("hello");
}
public void draw() {
rect(width/4, height/4, width/2, height/2);
synchronized(}
There is no newline after the final '}'. If I comment out the "synchronized" line and the
corresponding close bracket, the program compiles and runs successfully.
Thanks.
Additional Comment
#1 From fry 2005-08-23 12:58
verified.. preprocessor seems to be chewing up the code for some odd reason. perhaps the
grammar doesn't understand synchronized blocks for some odd reason?
Additional Comment
#2 From fry 2007-05-06 15:43
***
Bug 551
has been marked as a duplicate of this bug. ***
Additional Comment
#3 From moon 2007-12-24 09:45
I believe I saw that someone elsewhere already mentioned this (or alluded
to it): as a workaround, do all synchronized work in other tabs, .java
files. e.g. when I saw the preprocessor dirtnapping on synchronized, I
pushed my synchronized block in the .pde into a method on my subclass of
Thread. I'm using version 0135.
Additional Comment
#4 From fry 2008-05-29 15:48
Fixed in SVN for revision 0137.