/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.avro.specific;

import java.io.IOException;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.avro.AvroRuntimeException;
import org.apache.avro.Schema;
import org.apache.avro.io.DatumReader;
import org.apache.avro.io.ValueReader;
import org.apache.avro.reflect.ReflectDatumReader;

/** {@link DatumReader} for generated Java classes. */
public class SpecificDatumReader extends ReflectDatumReader {
  public SpecificDatumReader(String packageName) {
    super(packageName);
  }

  public SpecificDatumReader(Schema root, String packageName) {
    super(root, packageName);
  }

  protected Object newRecord(Object old, Schema schema) {
    Class c = getClass(schema.getName());
    return(c.isInstance(old) ? old : newInstance(c));
  }

  protected void addField(Object record, String name, int position, Object o) {
    ((SpecificRecord)record).set(position, o);
  }
  protected Object getField(Object record, String name, int position) {
    return ((SpecificRecord)record).get(position);
  }
  protected void removeField(Object record, String field, int position) {
    ((SpecificRecord)record).set(position, null);
  }

  private Map<String,Class> classCache = new ConcurrentHashMap<String,Class>();

  private Class getClass(String name) {
    Class c = classCache.get(name);
    if (c == null) {
      try {
        c = Class.forName(packageName + name);
        classCache.put(name, c);
      } catch (ClassNotFoundException e) {
        throw new AvroRuntimeException(e);
      }
    }
    return c;
  }

}

@@ -1495,167 +1495,8 @@
  %7D%0A%0A
-  protected Object newRecord(Object old, Schema schema) %7B%0A    Class c = getClass(schema.getName());%0A    return(c.isInstance(old) ? old : newInstance(c));%0A  %7D%0A%0A
   pr
@@ -1882,395 +1882,6 @@
  %7D%0A%0A
-  private Map%3CString,Class%3E classCache = new ConcurrentHashMap%3CString,Class%3E();%0A%0A  private Class getClass(String name) %7B%0A    Class c = classCache.get(name);%0A    if (c == null) %7B%0A      try %7B%0A        c = Class.forName(packageName + name);%0A        classCache.put(name, c);%0A      %7D catch (ClassNotFoundException e) %7B%0A        throw new AvroRuntimeException(e);%0A      %7D%0A    %7D%0A    return c;%0A  %7D%0A%0A
 %7D%0A

Remove some redundant code. Inherited methods are identical.