Bug: JavaScript error: resource:///modules/AddrBookCard.jsm, line 162: NS_ERROR_NOT_AVAILABLE: PopularityIndex: a - not an int
Status: RESOLVED
Priority: --
Resolution: FIXED
Created: 2021-10-22 21:34:42+00:00
Resolved: 2022-08-03 18:42:10+00:00

I noticed the following error in TB's xpcshell test log. This was done with DEBUG version of C-C TB.

I needed to run xpcshell test with "--verbose" and "--serialize" to obtain a sane readable log. This error IS HIDDEN if you run xpcshell test without such options.

```
 0:14.85 pid:21068 JavaScript error: resource:///modules/AddrBookCard.jsm, line 162: NS_ERROR_NOT_AVAILABLE: PopularityIndex: a - not an int
```

This error comes from the test, comm/mailnews/compose/test/unit/test_nsMsgCompose3.js.

I think this comes from the following line.
https://searchfox.org/comm-central/source/mailnews/compose/test/unit/test_nsMsgCompose3.js#85

```
 // Thunderbird 2 stored its popularityIndexes as hex, hence when we read it
    // now we're going to get a hex value. The AB has a value of "a".
    Assert.equal(
      card.getProperty("PopularityIndex", -1),
      TESTS[i].postPopularity
    );

```

I am not sure if the intent to support TB 2 addressbook/card format is working at all.

Probably the code that throws exception in AddrBookCard.jsm here needs modification.
https://searchfox.org/comm-central/source/mailnews/addrbook/modules/AddrBookCard.jsm#159
(not sure why the line number is slightly different. Maybe a slight local patch or something.)

```
  getPropertyAsUint32(name) {
    let value = this.getProperty(name);
    if (isNaN(parseInt(value, 10))) {
      throw Components.Exception(
	`${name}: ${value} - not an int`,
	Cr.NS_ERROR_NOT_AVAILABLE
      );
    }
    return value;
  },
```

The above does not support hex number at all.
It needs modification as in the following to support hexadecimal number. 
Not tested.

```
  getPropertyAsUint32(name) {
    let value = this.getProperty(name);
    let ival;
    if (isNaN(parseInt(value, 10))) {

      if (isNaN(parseInt(value, 16))) {
	 throw Components.Exception(
	   `${name}: ${value} - not an int`,
	 Cr.NS_ERROR_NOT_AVAILABLE
	 );
      } else {	// hex
	 ival = parseInt(value, 16);
      }
    } else { // decimal
       ival = parseInt(value, 10);
    }
    return ival;
  },
```
This error seems to have been in the log for quite some time.

I checked as far back to the beginning of 2020.

In January 2020, it appeared as uncaught exception probably.

```
28:08.18 INFO "Creating /NEW-SSD/moz-obj-dir/objdir-tb3/temp/xpc-profile-rFCxnZ/abook.sqlite from /NEW-SSD/moz-obj-dir/objdir-tb3/_tests/xpcshell/comm/mailnews/data/tb2hexpopularity.sql"
28:11.47 PASS run_test - [run_test : 69] true == true
28:11.69 PASS run_test - [run_test : 73] "a" == "a"
28:20.25 pid:592276 JavaScript error: /NEW-SSD/moz-obj-dir/objdir-tb3/_tests/xpcshell/comm/mailnews/compose/test/unit/test_nsMsgCompose3.js, line 56: uncaught exception: 2147746065
28:21.99 PASS checkPopulate - [checkPopulate : 56] true == true
```

It also appeared in Sept 2020. But for mysterious reasons, the test was not run for many months last year at least locally.

Maybe I missed the shuffling of directories then. 
(I had to run the test serially by subdirectory wise to obtain comparable sane log and in enumerating the subdirectories for testing, I may have failed to follow the change of directory hierarchy. 
Or maybe the particular subdirectory was declared to "skip" by test framework.)

Sept 30, 2020 log:
```
  -rw-r--r--  1 ishikawa ishikawa  2107575  9月 30  2020 log1252-xpctest.txt.gz
 0:16.90 INFO "Creating /NEW-SSD/moz-obj-dir/objdir-tb3/temp/xpc-profile-id6zq22t/abook.sqlite from /NEW-SSD/moz-obj-dir/objdir-tb3/_tests/xpcshell/comm/mailnews/data/tb2hexpopularity.sql"
 0:16.97 PASS run_test - [run_test : 69] true == true
 0:16.97 PASS run_test - [run_test : 73] "a" == "a"
 0:17.08 pid:793402 JavaScript error: resource:///modules/AddrBookCard.jsm, line 164: NS_ERROR_NOT_AVAILABLE: PopularityIndex: a - not an int
 0:17.10 PASS checkPopulate - [checkPopulate : 56] true == true
```

Full log is attached.