realrolfje/anonimatron

Null ponter exception if there's a discriminator without a corresponding top level column

Closed this issue · 3 comments

Describe the bug
The config below produces a java.lang.NullPointerException

    <table name="wp_usermeta">
        <discriminator columnname="meta_key" value="first_name">
            <column name="meta_value" type="ROMAN_NAME"/>
        </discriminator>
   </table>

The config below does not, but then it anonymizes every meta_value entry:

    <table name="wp_usermeta">
        <column name="meta_value"/>
        <discriminator columnname="meta_key" value="first_name">
            <column name="meta_value" type="ROMAN_NAME"/>
        </discriminator>
    </table>

To Reproduce
Steps to reproduce the behavior:

  1. Create a database with the following contents:
wp_usermeta

meta_key: test, meta_value: don't anonymize
meta_key:first_name, meta_value: Bob A. Nonymizeme
  1. Configure Anonimatron as follows:
<?xml version="1.0" encoding="UTF-8"?>
<configuration jdbcurl="jdbc:mysql://localhost:3306/anon" userid="anon_user" password="1q2w3e4r">
    <table name="wp_usermeta">
        <discriminator columnname="meta_key" value="first_name">
            <column name="meta_value" type="ROMAN_NAME"/>
        </discriminator>
    </table>
</configuration>
  1. Start with the following command:
./anonimatron.sh -config config.xml -synonyms synonyms.xml
  1. See error in log:
Reading Synonyms from /vagrant/anonimatron-1.12/synonyms.xml ...[done].

Anonymization process started

Jdbc url      : jdbc:mysql://localhost:3306/anon
Database user : anon_user
To do         : 1 tables.

Pre-scanning table 'wp_usermeta', total progress  [6%, ETA 1:30:20 AM]Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
	at com.rolfje.anonimatron.jdbc.JdbcAnonymizerService.processTableColumns(JdbcAnonymizerService.java:227)
	at com.rolfje.anonimatron.jdbc.JdbcAnonymizerService.preScanTable(JdbcAnonymizerService.java:118)
	at com.rolfje.anonimatron.jdbc.JdbcAnonymizerService.anonymize(JdbcAnonymizerService.java:72)
	at com.rolfje.anonimatron.Anonimatron.anonymize(Anonimatron.java:90)
	at com.rolfje.anonimatron.Anonimatron.main(Anonimatron.java:44)
Caused by: java.lang.NullPointerException
	at com.rolfje.anonimatron.jdbc.JdbcAnonymizerService.getSelectStatement(JdbcAnonymizerService.java:321)
	at com.rolfje.anonimatron.jdbc.JdbcAnonymizerService.processTableColumns(JdbcAnonymizerService.java:158)
	... 4 more
/vagrant/anonimatron-1.12

Expected behavior
Only alters rows with a meta_key of first_name. Leaves all other rows unchanged.

Desktop (please complete the following information):

  • OS: macOS 10.15.3
  • Java version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)

That is a very detailed bug report, thank you for that! I'll look into this.

This was an interesting bug. It turned out that column definitions which are in the discriminator, but not in the table configuration cause anonimatron to not process that column, and when fixed, it would not anonimyze any of the columns in the discriminator configuration.
I added a test and a fix, this should solve the problem.
From release 1.14, you will be able to have a table configuration with just a descriminator containing column definitions.

Merged a fix for this issue to the develop branch, and should be part of release 1.14 of anonimatron.