<commit_before>package org.mutabilitydetector.checkers;

import static org.mutabilitydetector.checkers.AccessModifierQuery.field;
import static org.mutabilitydetector.locations.FieldLocation.fieldLocation;

import org.mutabilitydetector.MutabilityReason;
import org.mutabilitydetector.locations.ClassLocation;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Type;

public class ArrayFieldMutabilityChecker extends AbstractMutabilityChecker {

    @Override
    public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
        /*
         * Static fields should not count against the instance.
         */
        if (field(access).isNotStatic()) {
            /*
             * This check was causing far too many classes to be called mutable. It would be better if it was possible
             * to check that an inherently mutable type was *actually mutated*. Calling an entire class mutable for
             * having a mutable field which it doesn't mutate is a bit rubbish.
             */
            if (isPrimitiveArray(desc) && !isTheInternalImmutableArrayFieldInAnEnum(name)) {
                addResult("Field is a primitive array.",
                        fieldLocation(name, ClassLocation.fromInternalName(ownerClass)),
                        MutabilityReason.ARRAY_TYPE_INHERENTLY_MUTABLE);
            }
        }

        return super.visitField(access, name, desc, signature, value);<commit_msg>This checker does not know if an array is primitive or not (vs. reference), so change error message to reflect that.<commit_after>package org.mutabilitydetector.checkers;

import static org.mutabilitydetector.checkers.AccessModifierQuery.field;
import static org.mutabilitydetector.locations.FieldLocation.fieldLocation;

import org.mutabilitydetector.MutabilityReason;
import org.mutabilitydetector.locations.ClassLocation;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Type;

public class ArrayFieldMutabilityChecker extends AbstractMutabilityChecker {

    @Override
    public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
        /*
         * Static fields should not count against the instance.
         */
        if (field(access).isNotStatic()) {
            /*
             * This check was causing far too many classes to be called mutable. It would be better if it was possible
             * to check that an inherently mutable type was *actually mutated*. Calling an entire class mutable for
             * having a mutable field which it doesn't mutate is a bit rubbish.
             */
            if (isPrimitiveArray(desc) && !isTheInternalImmutableArrayFieldInAnEnum(name)) {
                addResult("Field is an array.",
                        fieldLocation(name, ClassLocation.fromInternalName(ownerClass)),
                        MutabilityReason.ARRAY_TYPE_INHERENTLY_MUTABLE);
            }
        }

        return super.visitField(access, name, desc, signature, value);
{'fraction_non_alphanumeric': 0.06865965834428384, 'fraction_numerical': 0.0, 'mean_word_length': 2.975195822454308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1096106', 'n_tokens_mistral': 758, 'n_tokens_neox': 737, 'n_words': 236}