]> git.mxchange.org Git - addressbook-core.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Mon, 22 Aug 2016 15:39:32 +0000 (17:39 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 9 Jun 2017 19:34:00 +0000 (21:34 +0200)
- maybe I missunderstood this whole thing ... ;-(

src/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java

index 6acf8629247a2839250cdd8e981208950a5d920b..dbdcbc6e493ae7ec6b40ac5c7176954042208010 100644 (file)
@@ -82,8 +82,14 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                        // Fetch it from entity manager
                        DialableMobileNumber fetchedNumber = this.getEntityManager().getReference(MobileNumber.class, contact.getContactMobileNumber().getPhoneId());
 
-                       // Copy mobile number
-                       contact.setContactMobileNumber(this.getDetached(contact.getContactMobileNumber(), fetchedNumber));
+                       // Get detached number
+                       DialableMobileNumber detachedNumber = this.getDetached(contact.getContactMobileNumber(), fetchedNumber);
+
+                       // Is it null?
+                       if (detachedNumber instanceof DialableMobileNumber) {
+                               // Copy mobile number
+                               contact.setContactMobileNumber(detachedNumber);
+                       }
                }
 
                // Debug message
@@ -94,8 +100,14 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                        // Fetch it from entity manager
                        DialableLandLineNumber fetchedNumber = this.getEntityManager().getReference(LandLineNumber.class, contact.getContactLandLineNumber().getPhoneId());
 
-                       // Copy land-line number
-                       contact.setContactLandLineNumber(this.getDetached(contact.getContactLandLineNumber(), fetchedNumber));
+                       // Get detached number
+                       DialableLandLineNumber detachedNumber = this.getDetached(contact.getContactLandLineNumber(), fetchedNumber);
+
+                       // Is it null?
+                       if (detachedNumber instanceof DialableLandLineNumber) {
+                               // Copy mobile number
+                               contact.setContactLandLineNumber(detachedNumber);
+                       }
                }
 
                // Debug message
@@ -106,8 +118,14 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                        // Fetch it from entity manager
                        DialableFaxNumber fetchedNumber = this.getEntityManager().getReference(FaxNumber.class, contact.getContactFaxNumber().getPhoneId());
 
-                       // Copy fax number
-                       contact.setContactFaxNumber(this.getDetached(contact.getContactFaxNumber(), fetchedNumber));
+                       // Get detached number
+                       DialableFaxNumber detachedNumber = this.getDetached(contact.getContactFaxNumber(), fetchedNumber);
+
+                       // Is it null?
+                       if (detachedNumber instanceof DialableFaxNumber) {
+                               // Copy mobile number
+                               contact.setContactFaxNumber(detachedNumber);
+                       }
                }
 
                // Trace message
@@ -201,8 +219,8 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                // Debug message
                this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.getDetached: foundNumber={1}", this.getClass().getSimpleName(), foundNumber)); //NOI18N
 
-               // Default is fetched number
-               DialableMobileNumber detachedNumber = fetchedNumber;
+               // Default is null
+               DialableMobileNumber detachedNumber = null;
 
                // Is there a difference?
                if (!PhoneUtils.isSameMobileNumber(mobileNumber, fetchedNumber)) {
@@ -233,6 +251,9 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                if (null == landLineNumber) {
                        // Throw NPE
                        throw new NullPointerException("landLineNumber is null"); //NOI18N
+               } else if (null == fetchedNumber) {
+                       // Throw NPE again
+                       throw new NullPointerException("fetchedNumber is null"); //NOI18N
                } else if (fetchedNumber.getPhoneId() == null) {
                        // ..and again
                        throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
@@ -279,6 +300,9 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                if (null == faxNumber) {
                        // Throw NPE
                        throw new NullPointerException("faxNumber is null"); //NOI18N
+               } else if (null == fetchedNumber) {
+                       // Throw NPE again
+                       throw new NullPointerException("fetchedNumber is null"); //NOI18N
                } else if (fetchedNumber.getPhoneId() == null) {
                        // ..and again
                        throw new NullPointerException("fetchedNumber.phoneId is null"); //NOI18N