You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Serge Tsv (JIRA)" <ji...@apache.org> on 2008/02/23 12:17:19 UTC

[jira] Created: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

'java.lang.NullPointerException' is thrown when starting a master db before a slave one
---------------------------------------------------------------------------------------

                 Key: DERBY-3454
                 URL: https://issues.apache.org/jira/browse/DERBY-3454
             Project: Derby
          Issue Type: Bug
          Components: Replication
    Affects Versions: 10.4.0.0
            Reporter: Serge Tsv


The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.

The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
    MasterController#setupConnection
       -> transmitter = new ReplicationMessageTransmit(); 
            transmitter.initConnection()
              -> new InetSocketAddress() -> createSocket() -> connect()

The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 

A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.

Thanks!

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


[jira] Updated: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

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

V.Narayanan updated DERBY-3454:
-------------------------------

    Attachment: Derby3454.stat
                Derby3454.diff

Pls find attached a patch. Below is a file by file explanation of the
patch attached.

M      java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageTransmit.java

* Introduced not null checks for sockConn in tearDown
* Introduced a method that throws an exception if sockConn is null and used it
  in the methods that send and receive messages.

M      java/engine/org/apache/derby/impl/services/replication/net/ReplicationMessageReceive.java

* The changes to this file are identical to changes done on ReplicationMessageTransmit
  except that I change some places where sockConn is called directly to send messages
  to use the sendMessage method instead.

M      java/engine/org/apache/derby/loc/messages.xml
M      java/shared/org/apache/derby/shared/common/reference/MessageId.java

* Introduced one Message for the IOException that is thrown upon SocketConnection object being
null

I ran the repro. Pls find the repro output below.

ij> connect 'jdbc:derby://localhost:1527/replicationdb';
ij> connect 'jdbc:derby://localhost:1527/replicationdb;startMaster=true;slaveHost=localhost;slavePort=8002';
ERROR XRE04: DERBY SQL error: SQLCODE: -1, SQLSTATE: XRE04, SQLERRMC: replicationdblocalhost8002XRE04
ij> connect 'jdbc:derby://localhost:1527/replicationdb;startMaster=true;slaveHost=localhost;slavePort=8003';
ERROR XRE04: DERBY SQL error: SQLCODE: -1, SQLSTATE: XRE04, SQLERRMC: replicationdblocalhost8002XRE04
ij> connect 'jdbc:derby://localhost:1527/replicationdb;startMaster=true;slaveHost=localhost;slavePort=8001';
ERROR XRE04: DERBY SQL error: SQLCODE: -1, SQLSTATE: XRE04, SQLERRMC: replicationdblocalhost8002XRE04
ij>

You don't see the null pointer exceptions any more.

8001 is the correct port. The connection with the correct port also fails because of Derby-3358.

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Assigned: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

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

V.Narayanan reassigned DERBY-3454:
----------------------------------

    Assignee: V.Narayanan

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Updated: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

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

V.Narayanan updated DERBY-3454:
-------------------------------

    Derby Info: [Patch Available]

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Commented: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "V.Narayanan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574095#action_12574095 ] 

V.Narayanan commented on DERBY-3454:
------------------------------------

Thank you for trying out the patch Serge :)

>Could it be considered to throw a runtime exception
>(like an IllegalStateException) other then an IOException 
>in the case when we try to use a connection which hasn't 
>been established (except for a tearDown method)?

I do not think it is advisable to throw unchecked exceptions
unless in cases where an alternate checked exception is not
possible

>I think the receiver/transmitter shouldn't be accessed at all 
>after an exception is thrown during an initialization, which is 
>a case when socket couldn't be established.

A receiver or an transmitter is an abstraction above the underlying
connection. Why do you think accessing the transmitter or receiver is
wrong?

I do agree that attempting a send from the transmitter seems illogical
when the connection does not exist, but then the transmitter is an
abstraction above the connection and is insulated from the conenction
details. Only when it tries to access the underlying connection does
it know that the connection is no longer valid and gets an exception.

>The XRE04 error will still be reported in this case. And if the 
>runtime exception is used, then an introduction of a new error 
>message won't be required I guess. 

If this had been true the NPE (which is also a RuntimeException)
would have resulted in a XRE04 :). I do not think we will get a
XRE04 if a RuntimeException is thrown.

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Commented: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "V.Narayanan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12572196#action_12572196 ] 

V.Narayanan commented on DERBY-3454:
------------------------------------

tearDown is called in the startMaster method. The start failure and consequently the tearDown 
is caused by the failure to establish a socket connection. Hence in the tearDown method 
trying to send a STOP message through a socket that does not exist results in a 
NullPointerException.

All the public methods of ReplicationMessageTransmit and ReplicationMessageReceive should
ensure that the socket connection exists (is not null) before performing the respective
operations. If the socket connection does not exist readMessage returns null and the sendMessage
method returns quietly.

Methods in ReplicationMessageTransmit
-------------------------------------

* tearDown()
* sendMessage()
* readMessage()

Methods in ReplicationMessageReceive
------------------------------------

* sendMessage()
* readMessage()


The other methods in these classes must use the sendMessage and the readMessage methods and not
call socketConn.writeMessage, socketConn.readMessage on their own. This would ensure that
"socket connection connection exist" checks are restricted to the read and the write methods only.

Note: The case of active=false on the master and the transmitter being called to send a message
      is a unique case. This happens only when the tearDown is called because of a network(socket)
      connection failure. Hence here it is safe to exit quietly from a send or read attempt on a
      non-existent socket.

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Resolved: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

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

V.Narayanan resolved DERBY-3454.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 10.4.0.0

All relevant patches have been submitted and committed.
Resolving issue!

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>             Fix For: 10.4.0.0
>
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Commented: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "Øystein Grøvlen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574414#action_12574414 ] 

Øystein Grøvlen commented on DERBY-3454:
----------------------------------------

Thanks for the patch, Narayanan.  Looks good.  Committed as revision 633026.

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Commented: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "Serge Tsv (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12571721#action_12571721 ] 

Serge Tsv commented on DERBY-3454:
----------------------------------

This problem could be reproduced by simply creating a connection with a startMaster=true to an unestablished socket.

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Commented: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "V.Narayanan (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574826#action_12574826 ] 

V.Narayanan commented on DERBY-3454:
------------------------------------

Thank you for the comments Serge :)

>For the flow above:
>   * If (3) is executed before (2), then I guess this would be a programmatic error 
>     and a RE should be called (like IllegalStateException)

I would try to correct the case when (3) is called before (2) (fix the programming error)
than throw an IllegalStateException


>   * If (2) fails, I do also consider executing (3) after that as a programmatic error, 
>      because in this case a transmitter/receiver hasn't been properly initialized. 
>      And there's an attempt to use a transmitter/receiver which has turned up to
>      be in an illegal state.

>You're right that the transmitter/receiver is an abstraction above the connection.
>But I'm just trying to say that it might be wrong (from a programmatic point of view)
>to try to use them in an illegal state. And might be better to properly process a (2)
>failure and make it so sendMessage/readMessage methods won't be called 
>afterwards, instead of relying on an IOException been reported to a user.

* If there is a programmatic error causing an Unchecked Exception to be thrown (like an NPE)
  I would not correct it by throwing another Unchecked Exception (IllegalStateException)

* If there is a programmatic error that causes an Unchecked Exception to be thrown,like, (3)
  before (2) I would correct the programmatic error than throw an unchecked exception

* I do not agree that Properly processing a (2) failure = throwing an unchecked exception.

* I am properly processing (2) when I try to ensure that the underlying connection is valid
  before attempting a send or a receive.

* Now that all transmitter methods verify that the underlying connection is not invalid using
  the checkSocketConnection() method the there would be no danger of attempting (3) with a
  invalid connection.

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Commented: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "Øystein Grøvlen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574416#action_12574416 ] 

Øystein Grøvlen commented on DERBY-3454:
----------------------------------------

Forgot to comment that I feel the message text for R012 could be improved.
I suggest: "No replication connection for database <dbname>.


> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Updated: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "Øystein Grøvlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Øystein Grøvlen updated DERBY-3454:
-----------------------------------

    Derby Info:   (was: [Patch Available])

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Commented: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "Serge Tsv (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574091#action_12574091 ] 

Serge Tsv commented on DERBY-3454:
----------------------------------

Hello!

Have applied the patch to the trunk, and I see the same XRE04 error instread of NPE now. :-) 
I assume that it verifies that the tearDown method is implemented properly now.

I have a one small suggestion though. Could it be considered to throw a runtime exception 
(like an IllegalStateException) other then  an IOException in the case when we try to use a 
connection which hasn't been established (except for a tearDown method)? I think the 
receiver/transmitter shouldn't be accessed at all after an exception is thrown during an 
initialization, which is a case when socket couldn't be established. 

The XRE04 error will still be reported in this case. And if the runtime exception is used, 
then an introduction of a new error message won't be required I guess.

Thanks!

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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


[jira] Commented: (DERBY-3454) 'java.lang.NullPointerException' is thrown when starting a master db before a slave one

Posted by "Serge Tsv (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-3454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12574612#action_12574612 ] 

Serge Tsv commented on DERBY-3454:
----------------------------------

V.Narayanan, thanks for your comments!

I see the following generic use case for receiver/transmitter classes:

1. A receiver/transmitter instance is created.
2. An initConnection method is called on the created instance
3. sendMessage/readMessage calls are executed on the initialized 
     receiver/transmitter instance

For the flow above:
   * If (3) is executed before (2), then I guess this would be a programmatic error 
     and a RE should be called (like IllegalStateException)
   * If (2) fails, I do also consider executing (3) after that as a programmatic error, 
      because in this case a transmitter/receiver hasn't been properly initialized. 
      And there's an attempt to use a transmitter/receiver which has turned up to
      be in an illegal state.

You're right that the transmitter/receiver is an abstraction above the connection.
But I'm just trying to say that it might be wrong (from a programmatic point of view)
to try to use them in an illegal state. And might be better to properly process a (2)
failure and make it so sendMessage/readMessage methods won't be called 
afterwards, instead of relying on an IOException been reported to a user.

> If this had been true the NPE (which is also a RuntimeException)
would have resulted in a XRE04 :).

I think that XRE04 is thrown by an initConnection method. The NPE was caused 
by a tearDown method, and now it's been fixed, and there're no further calls to
sendMessage/readMessage in case of XRE04.

Thanks!

> 'java.lang.NullPointerException' is thrown when starting a master db before a slave one
> ---------------------------------------------------------------------------------------
>
>                 Key: DERBY-3454
>                 URL: https://issues.apache.org/jira/browse/DERBY-3454
>             Project: Derby
>          Issue Type: Bug
>          Components: Replication
>    Affects Versions: 10.4.0.0
>            Reporter: Serge Tsv
>            Assignee: V.Narayanan
>         Attachments: Derby3454.diff, Derby3454.stat
>
>
> The 'java.lang.NullPointerException' exception is thrown when a database is started in a master mode and is trying to establish a connection to an slave database socket, which is not available.
> The exception is by the MasterController#startMaster(). First, it tries to setup connection with a slave database using a transmitter:
>     MasterController#setupConnection
>        -> transmitter = new ReplicationMessageTransmit(); 
>             transmitter.initConnection()
>               -> new InetSocketAddress() -> createSocket() -> connect()
> The connect() method throws a ConnectException, and so fails to create a socketConn instance. The exception is then wrapped several times an propagated back to the MasterController#startMaster() method. It's caught there and then a MasterController#teardownNetwork() method is called, which tries to send a STOP message using the aforementioned transmitter, which hasn't been able to init a connection. 
> A transmitter simply tries to call socketConn.writeMessage(message), which throws NPE because socketConn is null.
> Thanks!

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