UPD: small coverity changes
authorBenny Baumann <BenBE@geshi.org>
Sat, 28 Feb 2015 21:39:57 +0000 (22:39 +0100)
committerFelix Dörre <felix@dogcraft.de>
Sat, 28 Feb 2015 21:53:04 +0000 (22:53 +0100)
src/org/cacert/gigi/DevelLauncher.java
src/org/cacert/gigi/dbObjects/User.java
tests/org/cacert/gigi/pages/wot/TestAssurance.java

index e66b915..9f1bf06 100644 (file)
@@ -77,7 +77,12 @@ public class DevelLauncher {
             instF.setAccessible(true);
             pageF.setAccessible(true);
             Object gigi = instF.get(null);
-            HashMap<String, Page> pages = new HashMap<>((Map<String, Page>) pageF.get(gigi));
+
+            // Check if we got a proper map (as much as we can tell)
+            Object pagesObj = pageF.get(gigi);
+            @SuppressWarnings("unchecked")
+            HashMap<String, Page> pages = pagesObj instanceof Map ? new HashMap<>((Map<String, Page>) pagesObj) : null;
+
             pages.put("/manage", new Page("Page-manager") {
 
                 @Override
index 1c9448b..e1425fe 100644 (file)
@@ -27,7 +27,9 @@ public class User extends CertificateOwner {
 
     private String email;
 
-    private Assurance[] receivedAssurances, madeAssurances;
+    private Assurance[] receivedAssurances;
+
+    private Assurance[] madeAssurances;
 
     private Locale locale;
 
@@ -255,33 +257,35 @@ public class User extends CertificateOwner {
     }
 
     public void updateDefaultEmail(EmailAddress newMail) throws GigiApiException {
-        EmailAddress[] adrs = getEmails();
-        for (int i = 0; i < adrs.length; i++) {
-            if (adrs[i].getAddress().equals(newMail.getAddress())) {
-                if ( !adrs[i].isVerified()) {
+        for (EmailAddress email : getEmails()) {
+            if (email.getAddress().equals(newMail.getAddress())) {
+                if ( !email.isVerified()) {
                     throw new GigiApiException("Email not verified.");
                 }
+
                 GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE users SET email=? WHERE id=?");
                 ps.setString(1, newMail.getAddress());
                 ps.setInt(2, getId());
                 ps.execute();
-                email = newMail.getAddress();
+
+                this.email = newMail.getAddress();
                 return;
             }
         }
+
         throw new GigiApiException("Given address not an address of the user.");
     }
 
-    public void deleteEmail(EmailAddress mail) throws GigiApiException {
-        if (getEmail().equals(mail.getAddress())) {
+    public void deleteEmail(EmailAddress delMail) throws GigiApiException {
+        if (getEmail().equals(delMail.getAddress())) {
             throw new GigiApiException("Can't delete user's default e-mail.");
         }
-        EmailAddress[] emails = getEmails();
-        for (int i = 0; i < emails.length; i++) {
-            if (emails[i].getId() == mail.getId()) {
+
+        for (EmailAddress email : getEmails()) {
+            if (email.getId() == delMail.getId()) {
                 GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE emails SET deleted=? WHERE id=?");
                 ps.setDate(1, new Date(System.currentTimeMillis()));
-                ps.setInt(2, mail.getId());
+                ps.setInt(2, delMail.getId());
                 ps.execute();
                 return;
             }
@@ -467,6 +471,7 @@ public class User extends CertificateOwner {
     }
 
     public boolean canIssue(CertificateProfile p) {
+        // FIXME: Use descriptive constants
         switch (p.getCAId()) {
         case 0:
             return true;
index a1d6194..9fae5dd 100644 (file)
@@ -27,20 +27,17 @@ public class TestAssurance extends ManagedTest {
 
     private String assureeM;
 
-    private int assurer;
-
-    private int assuree;
-
     private String cookie;
 
     @Before
     public void setup() throws IOException {
         assurerM = createUniqueName() + "@cacert-test.org";
         assureeM = createUniqueName() + "@cacert-test.org";
-        assurer = createAssuranceUser("a", "b", assurerM, TEST_PASSWORD);
-        assuree = createVerifiedUser("a", "c", assureeM, TEST_PASSWORD);
-        cookie = login(assurerM, TEST_PASSWORD);
 
+        createAssuranceUser("a", "b", assurerM, TEST_PASSWORD);
+        createVerifiedUser("a", "c", assureeM, TEST_PASSWORD);
+
+        cookie = login(assurerM, TEST_PASSWORD);
     }
 
     @Test