You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Rick Curtis (JIRA)" <ji...@apache.org> on 2009/07/09 00:01:15 UTC

[jira] Created: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

NPE in UUIDGenerator.initializeForType1()
-----------------------------------------

                 Key: OPENJPA-1168
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
             Project: OpenJPA
          Issue Type: Bug
          Components: lib
            Reporter: Rick Curtis
            Assignee: Rick Curtis
             Fix For: 1.3.0, 2.0.0


When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.

Scenario:
Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12728994#action_12728994 ] 

Michael Dick commented on OPENJPA-1168:
---------------------------------------

Hi Rick,

I'm unable to hit the timing window you mention on my system, but your explanation is sound. 

That said there's still a window where IP can be initialized (non null) but not copied. Another thread could hit this window when IP was empty and get a non-unique id. It's probably safer to set a different flag at the end of the method and key off that instead of IP or RANDOM.

Thanks for the patch though - I doubt this was easy to find.  

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Rick Curtis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rick Curtis updated OPENJPA-1168:
---------------------------------

    Attachment: OPENJPA-1168.patch

Nice catch Mike. 

I updated the patch as recommended.

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>            Assignee: Michael Dick
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Milosz Tylenda (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12729310#action_12729310 ] 

Milosz Tylenda commented on OPENJPA-1168:
-----------------------------------------

This reminds me of a test case which sometimes fails for me while running against MySQL and which I did not have time to look at. Maybe this is connected although the test case is single-threaded. The stack trace I am receiving is:

testDefaultValues(org.apache.openjpa.persistence.generationtype.TestGeneratedValues)  Time elapsed: 0.787 sec  <<< FAILURE!
junit.framework.AssertionFailedError
        at junit.framework.Assert.fail(Assert.java:47)
        at junit.framework.Assert.assertTrue(Assert.java:20)
        at junit.framework.Assert.assertFalse(Assert.java:34)
        at junit.framework.Assert.assertFalse(Assert.java:41)
        at org.apache.openjpa.persistence.generationtype.TestGeneratedValues.testDefaultValues(TestGeneratedValues.java:49)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at org.apache.openjpa.persistence.test.PersistenceTestCase.runBare(PersistenceTestCase.java:466)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at org.apache.openjpa.persistence.test.PersistenceTestCase.run(PersistenceTestCase.java:181)
        at junit.framework.TestSuite.runTest(TestSuite.java:208)
        at junit.framework.TestSuite.run(TestSuite.java:203)
        at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
        at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

The TestGeneratedValues.java:49 contains:

        assertFalse(gv.getUuidstring().equals(gv2.getUuidstring()));

This means UUID generator sometimes generates duplicates.


> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>            Assignee: Michael Dick
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch, OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Rick Curtis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rick Curtis updated OPENJPA-1168:
---------------------------------

    Attachment: OPENJPA-1168.patch

Fixed a problem in the test case that was introduced because of the previous patch.

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>            Assignee: Michael Dick
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch, OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Rick Curtis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rick Curtis updated OPENJPA-1168:
---------------------------------

    Attachment: OPENJPA-1168.patch

The patch includes a test case and the fix for this issue. 

Since this bug is a timing window, running this test case against an un-patched tree may work from time to time. Please let me know if you want me to post some more information in the test case about why I did what I did.

- Rick

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>            Assignee: Rick Curtis
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Rick Curtis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rick Curtis updated OPENJPA-1168:
---------------------------------

    Attachment:     (was: OPENJPA-1168.patch)

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>            Assignee: Michael Dick
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Donald Woods (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Donald Woods updated OPENJPA-1168:
----------------------------------

    Fix Version/s:     (was: 2.0.0)
                   2.0.0-M3

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>            Assignee: Michael Dick
>             Fix For: 1.3.0, 2.0.0-M3
>
>         Attachments: OPENJPA-1168.patch, OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Dick resolved OPENJPA-1168.
-----------------------------------

    Resolution: Fixed

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>            Assignee: Michael Dick
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch, OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Dick reassigned OPENJPA-1168:
-------------------------------------

    Assignee: Michael Dick

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>            Assignee: Michael Dick
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1168) NPE in UUIDGenerator.initializeForType1()

Posted by "Rick Curtis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rick Curtis updated OPENJPA-1168:
---------------------------------

    Patch Info: [Patch Available]
      Assignee:     (was: Rick Curtis)

> NPE in UUIDGenerator.initializeForType1()
> -----------------------------------------
>
>                 Key: OPENJPA-1168
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1168
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: lib
>            Reporter: Rick Curtis
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-1168.patch
>
>
> When UUIDGenerator.createType1() is called by more than one thread at *nearly* the same time AND UUIDGenerator.createType1() wasn't called previously, a small timing window exists where a NPE will result.
> Scenario:
> Thread 1 calls UUIDGenerator.createType1() and RANDOM == null so initializeForType1() is called. While that thread is in initializeForType1(), it sets the static variable RANDOM so that value is no longer null. Now Thread 2 calls UUIDGenerator.createType1() and RANDOM is no longer null, so it proceeds to the call System.arraycopy(IP, 0, uuid, 10, IP.length);. At this point Thread 1 hasn't got to initializing IP yet, so Thread 2 gets hits a NPE.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.