Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-495

ConcurrentModificationException in UpdateTracker.getDirtyAreas()

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: None
    • Component/s: GVT
    • Labels:
      None
    • Environment:
      Operating System: Linux
      Platform: PC

      Description

      UpdateTracker is not intended to be
      thread safe, but UpdateTracker.changeStarted() is
      called outside the UpdateManager thread when resizing
      the SVGCanvas. sometimes this could finnish with a
      ConcurrentModificationException in UpdateManager... no more refreshing...

      Tested on linux mandrake 10.0,
      JDK: IBM JDK 1.4.1 and sun JDK 1.4.2_04
      batik 1.5.1

      Here is a test case:
      just save map.svg, compile TestSVG, run and resize several times the window.
      The program terminates as soon as RunnableQueue is broken (it takes only few
      seconds when resizing the window continuously).

      TestSVG.java:

      import java.util.Random;

      import javax.swing.JFrame;

      import org.apache.batik.swing.JSVGCanvas;
      import org.apache.batik.util.RunnableQueue;
      import org.w3c.dom.Element;
      import org.w3c.dom.NodeList;

      /**

      • @author yann
        */
        public class TestSVG extends JFrame {
        JSVGCanvas c;

      String nomsvg = "map.svg";

      public TestSVG() {
      super();
      c = new JSVGCanvas();

      c.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
      c.setEnableImageZoomInteractor(false);
      c.setEnablePanInteractor(false);
      c.setEnableResetTransformInteractor(false);
      c.setEnableRotateInteractor(false);
      c.setEnableZoomInteractor(false);
      c.setURI("file://" + nomsvg);

      getContentPane().add(c);
      setSize(400, 400);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      show();

      //wait until we can play...
      while (c.getUpdateManager() == null) {
      try

      { Thread.sleep(1000); } catch (InterruptedException ie) {
      }
      }
      while (c.getUpdateManager().getUpdateRunnableQueue() == null) {
      try { Thread.sleep(1000); }

      catch (InterruptedException ie) {
      }
      }
      RunnableQueue q = c.getUpdateManager().getUpdateRunnableQueue();

      // everything ok.
      int cpt = 0;
      while (true) { // modify continuously the svg document
      // the svgcanvas is often repainted
      // which make the problem appear soon
      cpt++;
      try {
      q.invokeLater(new Runnable() {
      public void run() {
      NodeList nl = c.getSVGDocument().getElementsByTagName(
      "path");
      for (int i = 0; i < nl.getLength(); i++)

      { Element e = (Element) nl.item(i); e.setAttribute("style", "fill:rgb(" + r.nextInt(255) + "," + r.nextInt(255) + "," + r.nextInt(255) + ")"); }

      }
      });
      if (cpt % 100 == 0)
      Thread.sleep(200);
      } catch (Exception e)

      { // RunnableQueue may be broken... IllegalStateException e.printStackTrace(); System.exit(0); }

      }

      }

      public static Random r = new Random();

      public static void main(String[] args)

      { new TestSVG(); }

      }

      map.svg:

      <?xml version="1.0" encoding="UTF-8"?>

      <svg nom="france" xmlns:xlink="http://www.w3.org/1999/xlink"
      preserveAspectRatio="xMidYMid" viewBox="-110 70 700 600">

      <path id="AI" d="M 473 349 456 353 432 344 418 377 440 387 462
      368 466 365 "/>
      <path id="AS" d="M 336 155 372 142 376 168 361 183 358 199 339
      167 337 161 "/>
      <path id="AL" d="M 380 365 353 341 341 334 330 348 331 375 358
      377 369 379 "/>
      <path id="AP" d="M 473 507 514 481 518 450 500 460 483 462 463
      483 468 502 "/>
      <path id="AH" d="M 487 422 507 457 490 464 473 472 469 451 488
      434 487 422 "/>
      <path id="AM" d="M 549 496 548 472 519 464 511 471 517 506 524
      514 543 497 "/>
      <path id="AD" d="M 425 458 425 447 405 436 393 447 387 454 407
      479 423 479 "/>
      <path id="AR" d="M 412 182 414 173 404 147 387 142 380 157 389
      181 398 181 "/>
      <path id="AG" d="M 291 586 266 571 283 552 300 546 304 552 313
      565 322 577 "/>
      <path id="AB" d="M 406 258 402 262 366 251 362 226 376 223 408
      234 406 252 "/>
      <path id="AU" d="M 330 571 348 569 361 567 343 544 321 535 315
      567 319 575 "/>
      <path id="AV" d="M 317 465 306 479 358 509 366 487 355 464 335
      452 333 457 "/>
      <path id="BR" d="M 418 515 459 510 470 516 444 532 448 528 442
      528 429 533 423 527 "/>
      <path id="CA" d="M 189 223 226 212 233 195 213 192 178 187 179
      215 179 223 "/>
      <path id="CL" d="M 367 441 349 458 346 450 315 452 323 421 328
      418 349 423 355 420 "/>
      <path id="CH" d="M 243 380 258 378 251 403 214 429 211 413 220
      392 233 380 "/>
      <path id="CM" d="M 181 365 193 373 220 392 222 432 176 396 179
      383 177 368 "/>
      <path id="CE" d="M 320 353 331 339 330 293 326 290 309 301 299
      313 307 333 "/>
      <path id="CZ" d="M 328 418 324 417 299 447 277 416 293 409 308
      400 327 397 "/>
      <path id="CS" d="M 552 609 551 617 545 634 532 627 516 600 519
      579 517 576 552 609 "/>
      <path id="HC" d="M 537 593 533 583 524 564 536 557 548 554 556
      550 555 561 552 602 "/>
      <path id="CR" d="M 390 285 395 269 403 261 427 278 439 310 427
      317 387 311 "/>
      <path id="CT" d="M 145 248 131 232 124 231 101 219 78 230 104
      258 123 261 "/>
      <path id="CU" d="M 329 373 314 358 288 359 281 368 290 389 305
      397 319 402 328 390 "/>
      <path id="DO" d="M 225 435 236 420 279 422 287 443 279 461 242
      465 222 439 "/>
      <path id="DU" d="M 472 341 470 330 455 312 477 281 488 276 494
      303 477 329 "/>
      <path id="DR" d="M 434 415 441 422 455 445 455 465 467 479 456
      482 425 458 430 438 "/>
      <path id="EU" d="M 236 209 232 194 233 188 260 192 288 184 281
      202 259 223 244 213 "/>
      <path id="EL" d="M 256 260 258 234 281 212 292 236 300 255 276
      268 263 258 260 261 "/>
      <path id="FI" d="M 74 282 60 272 43 250 54 243 51 227 79
      244 75 261 "/>
      <path id="GD" d="M 396 486 393 473 406 481 425 502 412 524 378
      506 373 500 "/>
      <path id="GH" d="M 247 582 250 558 263 540 293 509 299 521 286
      549 275 555 "/>
      <path id="GE" d="M 255 545 275 532 266 510 227 510 218 522 224
      531 246 544 255 545 "/>
      <path id="GI" d="M 187 421 199 439 226 454 232 465 226 483 201
      484 176 469 "/>
      <path id="HE" d="M 397 524 390 500 378 506 353 518 346 522 349
      541 353 537 368 545 "/>
      <path id="IV" d="M 141 252 137 231 148 231 181 248 182 270 139
      290 131 272 132 261 "/>
      <path id="IN" d="M 312 345 298 314 279 317 266 325 273 363 291
      360 295 357 312 358 "/>
      <path id="IL" d="M 276 323 265 337 247 326 236 330 228 308 258
      285 265 296 268 309 "/>
      <path id="IS" d="M 427 387 443 381 483 420 477 441 432 414 423
      412 428 393 "/>
      <path id="JU" d="M 453 311 473 327 440 346 439 330 438 320 435
      316 442 306 444 297 "/>
      <path id="LD" d="M 166 526 181 475 188 480 205 485 218 510 191
      531 178 535 175 533 "/>
      <path id="LC" d="M 299 313 312 294 292 283 266 262 254 267 267
      299 278 314 "/>
      <path id="LO" d="M 379 384 384 366 404 369 418 401 423 412 393
      416 387 416 378 394 "/>
      <path id="LH" d="M 393 416 409 421 405 437 393 447 382 447 367
      441 361 415 378 417 "/>
      <path id="LA" d="M 123 304 128 312 135 314 144 327 173 321 171
      310 176 289 "/>
      <path id="LE" d="M 335 279 345 264 327 256 300 255 297 284 329
      293 336 292 "/>
      <path id="LT" d="M 274 479 281 486 297 486 317 467 310 444 285
      452 280 458 272 469 "/>
      <path id="LG" d="M 231 463 228 482 231 500 256 502 271 481 263
      470 262 465 245 466 "/>
      <path id="LZ" d="M 351 461 379 446 390 463 392 478 396 485 359
      483 359 473 "/>
      <path id="ML" d="M 231 292 213 285 178 291 175 314 178 325 218
      322 231 296 "/>
      <path id="MA" d="M 160 223 160 208 152 169 172 173 176 219 191
      227 168 241 "/>
      <path id="MR" d="M 362 226 376 223 392 224 408 218 382 175 362
      193 356 214 360 225"/>
      <path id="MH" d="M 456 257 444 249 435 229 408 234 406 252 420
      274 431 278 437 278"/>
      <path id="MY" d="M 181 269 179 253 191 241 214 236 215 248 212
      258 209 266 204 281 "/>
      <path id="MM" d="M 493 212 466 203 457 195 452 174 448 190 447
      225 465 229 485 226 "/>
      <path id="MS" d="M 444 199 442 184 431 166 414 177 414 202 416
      215 437 230 "/>
      <path id="MO" d="M 137 286 132 273 120 267 102 256 76 267 95
      288 105 290 109 290 "/>
      <path id="ME" d="M 457 195 452 174 478 178 511 179 493 191 504
      199 506 202 "/>
      <path id="NI" d="M 353 341 366 341 384 333 383 301 378 297 363
      290 337 292 347 332 "/>
      <path id="NO" d="M 354 142 361 138 380 136 341 104 315 85 315
      108 335 125 339 141 "/>
      <path id="OI" d="M 286 173 285 164 320 167 339 167 338 180 339
      199 317 198 301 192 "/>
      <path id="OR" d="M 188 239 226 212 252 223 250 255 244 252 219
      241 209 238 188 239"/>
      <path id="PC" d="M 279 113 302 98 326 112 329 114 333 136 324
      139 312 131 280 125"/>
      <path id="PD" d="M 328 404 337 418 374 416 378 394 371 379 330
      386 326 392 "/>
      <path id="PA" d="M 206 576 196 567 154 541 166 536 211 531 227
      539 221 557 "/>
      <path id="PH" d="M 216 569 227 545 227 539 233 538 240 580 236
      580 222 577 "/>
      <path id="PO" d="M 306 591 314 594 325 596 361 590 357 566 351
      565 326 580 306 587 "/>
      <path id="RB" d="M 501 227 505 205 504 199 494 201 493 191 514
      190 530 182 526 208 "/>
      <path id="RH" d="M 507 272 502 268 502 234 525 269 511 279 507
      277 "/>
      <path id="RO" d="M 403 363 409 359 426 386 421 406 407 392 404
      385 398 375 404 365 "/>
      <path id="SH" d="M 437 285 457 295 486 278 491 264 489 258 479
      256 459 257 455 260 "/>
      <path id="SL" d="M 435 316 412 323 392 310 385 351 403 363 420
      366 442 331 "/>
      <path id="ST" d="M 256 260 247 251 236 238 232 239 212 262 204
      281 215 285 231 292 "/>
      <path id="SV" d="M 501 420 522 405 495 378 477 385 460 393 476
      403 481 420 492 425 "/>
      <path id="SA" d="M 466 365 464 366 471 385 480 385 491 375 495
      378 502 358 479 354 469 363 "/>
      <path id="SM" d="M 234 181 246 155 274 145 286 161 285 168 286
      181 279 179 249 182 "/>
      <path id="SE" d="M 321 205 322 198 339 199 356 214 360 225 336
      253 330 253 322 252 321 225 "/>
      <path id="YV" d="M 298 240 303 226 306 219 301 205 291 204 286
      225 298 240"/>
      <path id="SD" d="M 218 324 224 341 225 350 229 375 210 383 198
      360 199 352 191 328 "/>
      <path id="SO" d="M 324 139 310 136 299 134 298 129 272 143 286
      159 336 162 338 149 "/>
      <path id="TA" d="M 353 518 325 494 309 492 301 519 302 525 309
      530 325 534 339 525 350 519 "/>
      <path id="TG" d="M 264 497 274 483 292 489 297 486 306 482 284
      512 280 516 260 508 "/>
      <path id="VA" d="M 476 506 484 508 516 502 523 519 488 544 473
      537 472 520 474 509 "/>
      <path id="VU" d="M 468 502 462 493 455 482 451 480 439 475 427
      489 431 490 455 508 "/>
      <path id="VE" d="M 186 368 173 369 168 369 150 358 160 333 164
      329 173 324 181 326 198 360 "/>
      <path id="VI" d="M 218 324 224 341 225 350 229 368 233 377 265
      369 267 354 246 327 218 322 "/>
      <path id="VH" d="M 293 394 290 389 281 368 258 378 258 411 272
      412 273 416 284 412 305 403 "/>
      <path id="VO" d="M 495 260 504 230 499 219 472 227 450 224 447
      241 453 253 475 254 482 252 "/>
      <path id="YO" d="M 388 262 378 264 360 240 343 256 363 290 387
      299 395 273 392 264 "/>
      <path id="TB" d="M 493 260 499 262 507 272 504 277 495 275 493
      260 "/>
      <path id="ES" d="M 321 225 310 245 298 240 301 233 312 219 315
      220 317 220 320 221 321 222 "/>
      <path id="VS" d="M 291 196 308 196 321 201 315 206 308 208 297
      206 291 204 288 202 "/>
      <path id="IC" d="M 309 220 306 214 313 206 321 223 320 222 319
      220 315 220 313 220 312 219 "/>

      </svg>

      Here are stack traces for AWTEventDispatchThread (the code called when the
      canvas is resized) and
      the ConcurrentModificationException in UpdateManager (crash of the RunnableQueue):

      java.lang.Exception: Stack trace
      at java.lang.Thread.dumpStack(Thread.java:1103)
      at org.apache.batik.gvt.UpdateTracker.changeStarted(Unknown Source)
      at
      org.apache.batik.gvt.AbstractGraphicsNode.fireGraphicsNodeChangeStarted(Unknown
      Source)
      at
      org.apache.batik.gvt.AbstractGraphicsNode.fireGraphicsNodeChangeStarted(Unknown
      Source)
      at org.apache.batik.gvt.CanvasGraphicsNode.setViewingTransform(Unknown Source)
      at org.apache.batik.swing.svg.JSVGComponent.updateRenderingTransform(Unknown
      Source)
      at org.apache.batik.swing.gvt.JGVTComponent$1.componentResized(Unknown Source)
      at java.awt.AWTEventMulticaster.componentResized(AWTEventMulticaster.java:125)
      at java.awt.Component.processComponentEvent(Component.java:5120)
      at java.awt.Component.processEvent(Component.java:5074)
      at java.awt.Container.processEvent(Container.java:1607)
      at java.awt.Component.dispatchEventImpl(Component.java:3754)
      at java.awt.Container.dispatchEventImpl(Container.java:1664)
      at java.awt.Component.dispatchEvent(Component.java:3582)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:531)
      at
      java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:238)
      at
      java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:182)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:131)

      java.util.ConcurrentModificationException
      at java.util.HashMap$HashIterator.nextEntry(HashMap.java(Compiled Code))
      at java.util.HashMap$KeyIterator.next(HashMap.java(Compiled Code))
      at org.apache.batik.gvt.UpdateTracker.getDirtyAreas(Unknown Source)
      at org.apache.batik.bridge.UpdateManager.repaint(Unknown Source)
      at
      org.apache.batik.bridge.UpdateManager$UpdateManagerRunHander.runnableInvoked(Unknown
      Source)
      at org.apache.batik.util.RunnableQueue.runnableInvoked(Unknown Source)
      at org.apache.batik.util.RunnableQueue.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:568)

        Attachments

          Activity

            People

            • Assignee:
              batik-dev@xmlgraphics.apache.org Batik Developer's Mailing list
              Reporter:
              yg64588@yahoo.com yann génin
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: