ronantakizawa/codereview-bench huggingface dataset:
Repository: menloresearch/jan
File: web/context/FeatureToggle.tsx (TypeScript)

Code before:
}

export const FeatureToggleContext =
  createContext<FeatureToggleContextType>(initialContext)

export default function FeatureToggleWrapper({
  children,
}: {
  children: ReactNode
}) {
  const EXPERIMENTAL_FEATURE = 'experimentalFeature'
  const IGNORE_SSL = 'ignoreSSLFeature'
  const HTTPS_PROXY_FEATURE = 'httpsProxyFeature'
  const [experimentalFeature, directSetExperimentalFeature] = useState<boolean>(false)
  const [ignoreSSL, directSetIgnoreSSL] = useState<boolean>(false)
  const [proxy, directSetProxy] = useState<string>('')

  useEffect(() => {
    directSetExperimentalFeature(
      localStorage.getItem(EXPERIMENTAL_FEATURE) === 'true'
    )
    directSetIgnoreSSL(
      localStorage.getItem(IGNORE_SSL) === 'true'
    )
    directSetProxy(
      localStorage.getItem(HTTPS_PROXY_FEATURE)
    )
  }, [])

  const setExperimentalFeature = (on: boolean) => {
    localStorage.setItem(EXPERIMENTAL_FEATURE, on ? 'true' : 'false')
    directSetExperimentalFeature(on)
  }

  const setIgnoreSSL = (on: boolean) => {
    localStorage.setItem(IGNORE_SSL, on ? 'true' : 'false')
    directSetIgnoreSSL(on)
  }

  const setProxy = (proxy: string) => {
    localStorage.setItem(HTTPS_PROXY_FEATURE, proxy)
    directSetProxy(proxy)
  }

  return (
    <FeatureToggleContext.Provider
      value={{
        experimentalFeature,
        ignoreSSL,
        proxy,
        setExperimentalFeature,

Review comment (suggestion):
localStorage.getItem(HTTPS_PROXY_FEATURE) might return null.
```ts
Type error: Argument of type 'string | null' is not assignable to parameter of type 'SetStateAction<string>'.
  Type 'null' is not assignable to type 'SetStateAction<string>'
```

Code after:
}

export const FeatureToggleContext =
  createContext<FeatureToggleContextType>(initialContext)

export default function FeatureToggleWrapper({
  children,
}: {
  children: ReactNode
}) {
  const EXPERIMENTAL_FEATURE = 'experimentalFeature'
  const IGNORE_SSL = 'ignoreSSLFeature'
  const HTTPS_PROXY_FEATURE = 'httpsProxyFeature'
  const [experimentalFeature, directSetExperimentalFeature] = useState<boolean>(false)
  const [ignoreSSL, directSetIgnoreSSL] = useState<boolean>(false)
  const [proxy, directSetProxy] = useState<string>('')

  useEffect(() => {
    directSetExperimentalFeature(
      localStorage.getItem(EXPERIMENTAL_FEATURE) === 'true'
    )
    directSetIgnoreSSL(
      localStorage.getItem(IGNORE_SSL) === 'true'
    )
    directSetProxy(
      localStorage.getItem(HTTPS_PROXY_FEATURE) ?? ""
    )
  }, [])

  const setExperimentalFeature = (on: boolean) => {
    localStorage.setItem(EXPERIMENTAL_FEATURE, on ? 'true' : 'false')
    directSetExperimentalFeature(on)
  }

  const setIgnoreSSL = (on: boolean) => {
    localStorage.setItem(IGNORE_SSL, on ? 'true' : 'false')
    directSetIgnoreSSL(on)
  }

  const setProxy = (proxy: string) => {
    localStorage.setItem(HTTPS_PROXY_FEATURE, proxy)
    directSetProxy(proxy)
  }

  return (
    <FeatureToggleContext.Provider
      value={{
        experimentalFeature,
        ignoreSSL,
        proxy,
        setExperimentalFeature,
Repository: menloresearch/jan
File: web/context/FeatureToggle.tsx (TypeScript)

Code before:
}

export const FeatureToggleContext =
  createContext<FeatureToggleContextType>(initialContext)

export default function FeatureToggleWrapper({
  children,
}: {
  children: ReactNode
}) {
  const EXPERIMENTAL_FEATURE = 'experimentalFeature'
  const IGNORE_SSL = 'ignoreSSLFeature'
  const HTTPS_PROXY_FEATURE = 'httpsProxyFeature'
  const [experimentalFeature, directSetExperimentalFeature] = useState<boolean>(false)
  const [ignoreSSL, directSetIgnoreSSL] = useState<boolean>(false)
  const [proxy, directSetProxy] = useState<string>('')

  useEffect(() => {
    directSetExperimentalFeature(
      localStorage.getItem(EXPERIMENTAL_FEATURE) === 'true'
    )
    directSetIgnoreSSL(
      localStorage.getItem(IGNORE_SSL) === 'true'
    )
    directSetProxy(
      localStorage.getItem(HTTPS_PROXY_FEATURE)
    )
  }, [])

  const setExperimentalFeature = (on: boolean) => {
    localStorage.setItem(EXPERIMENTAL_FEATURE, on ? 'true' : 'false')
    directSetExperimentalFeature(on)
  }

  const setIgnoreSSL = (on: boolean) => {
    localStorage.setItem(IGNORE_SSL, on ? 'true' : 'false')
    directSetIgnoreSSL(on)
  }

  const setProxy = (proxy: string) => {
    localStorage.setItem(HTTPS_PROXY_FEATURE, proxy)
    directSetProxy(proxy)
  }

  return (
    <FeatureToggleContext.Provider
      value={{
        experimentalFeature,
        ignoreSSL,
        proxy,
        setExperimentalFeature,

Review comment (suggestion):
@markmehere, that's a really great PR. I'd like to apply this change to fix the compilation error, and then we'll be good to go.
```suggestion
      localStorage.getItem(HTTPS_PROXY_FEATURE) ?? ""
```

Code after:
}

export const FeatureToggleContext =
  createContext<FeatureToggleContextType>(initialContext)

export default function FeatureToggleWrapper({
  children,
}: {
  children: ReactNode
}) {
  const EXPERIMENTAL_FEATURE = 'experimentalFeature'
  const IGNORE_SSL = 'ignoreSSLFeature'
  const HTTPS_PROXY_FEATURE = 'httpsProxyFeature'
  const [experimentalFeature, directSetExperimentalFeature] = useState<boolean>(false)
  const [ignoreSSL, directSetIgnoreSSL] = useState<boolean>(false)
  const [proxy, directSetProxy] = useState<string>('')

  useEffect(() => {
    directSetExperimentalFeature(
      localStorage.getItem(EXPERIMENTAL_FEATURE) === 'true'
    )
    directSetIgnoreSSL(
      localStorage.getItem(IGNORE_SSL) === 'true'
    )
    directSetProxy(
      localStorage.getItem(HTTPS_PROXY_FEATURE) ?? ""
    )
  }, [])

  const setExperimentalFeature = (on: boolean) => {
    localStorage.setItem(EXPERIMENTAL_FEATURE, on ? 'true' : 'false')
    directSetExperimentalFeature(on)
  }

  const setIgnoreSSL = (on: boolean) => {
    localStorage.setItem(IGNORE_SSL, on ? 'true' : 'false')
    directSetIgnoreSSL(on)
  }

  const setProxy = (proxy: string) => {
    localStorage.setItem(HTTPS_PROXY_FEATURE, proxy)
    directSetProxy(proxy)
  }

  return (
    <FeatureToggleContext.Provider
      value={{
        experimentalFeature,
        ignoreSSL,
        proxy,
        setExperimentalFeature,
Repository: micronaut-projects/micronaut-core
File: core/src/main/java/io/micronaut/core/annotation/AnnotationValue.java (Java)

Code before:
        if (enumType.isInstance(o)) {
            return Optional.of((T) o);
        } else {
            try {
                T t = (T) Enum.valueOf(enumType, o.toString());
                return Optional.of(t);
            } catch (IllegalArgumentException ex) {
                return Optional.empty();
            }
        }
    }

    /**
     * Creates {@link AnnotationClassValue} from the class name.
     *
     * @param className The class name
     * @return AnnotationClassValue for given class name
     */
    private static AnnotationClassValue<?> getAnnotationClassValue(String className) {
        Optional<Class<?>> theClass = ClassUtils.forName(className, null);
        if (theClass.isPresent()) {
            return new AnnotationClassValue(theClass.get());
        }
        return new AnnotationClassValue<>(className);
    }
}


Review comment (suggestion):
The difference from previous version is that it was using classloader from `beanContext.getClassLoader()` and this will fallback to current thread classloader.
```
if (classLoader == null) {
                classLoader = Thread.currentThread().getContextClassLoader();
            }
            if (classLoader == null) {
                classLoader = ClassLoader.getSystemClassLoader();
            }
```
Not sure if this could cause other issues.

Code after:
            return valueMapper.apply(rawValue);
        }
        return rawValue;
    }

    private static <T extends Enum> Optional<T> convertToEnum(Class<T> enumType, Object o) {
        if (enumType.isInstance(o)) {
            return Optional.of((T) o);
        } else {
            try {
                T t = (T) Enum.valueOf(enumType, o.toString());
                return Optional.of(t);
            } catch (IllegalArgumentException ex) {
                return Optional.empty();
            }
        }
    }

    /**
     * Creates {@link AnnotationClassValue} from the class name.
     *
     * @param className The class name
     * @return AnnotationClassValue for given class name
     */
    private static AnnotationClassValue<?> getAnnotationClassValue(String className) {
        Optional<Class<?>> theClass = ClassUtils.forName(className, null);
        if (theClass.isPresent()) {
            return new AnnotationClassValue<>(theClass.get());
        }
        return new AnnotationClassValue<>(className);
    }
}
Repository: micronaut-projects/micronaut-core
File: http/src/main/java/io/micronaut/http/body/TypedMessageBodyReader.java (Java)

Code before:
package io.micronaut.http.body;

import io.micronaut.core.annotation.Experimental;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.type.Argument;
import io.micronaut.http.MediaType;

/**
 * A body reader {@link MessageBodyReader} with a type argument.
 *
 * @param <T> The type
 * @author Denis Stepanov
 * @since 4.6
 */
@Experimental
public interface TypedMessageBodyReader<T> extends MessageBodyReader<T> {

    /**
     * @return The body type.
     */
    @NonNull
    Argument<T> getType();

    @Override
    default boolean isReadable(Argument<T> type, MediaType mediaType) {
        return type.isAssignableFrom(getType());
    }
}


Review comment (suggestion):
I don't think this a correct fix, typed reader should only add a type and nothing else

Code after:
package io.micronaut.http.body;

import io.micronaut.core.annotation.Experimental;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.type.Argument;
import io.micronaut.http.MediaType;

/**
 * A body reader {@link MessageBodyReader} with a type argument.
 *
 * @param <T> The type
 * @author Denis Stepanov
 * @since 4.6
 */
@Experimental
public interface TypedMessageBodyReader<T> extends MessageBodyReader<T> {

    /**
     * @return The body type.
     */
    @NonNull
    Argument<T> getType();

    @Override
    default boolean isReadable(Argument<T> type, MediaType mediaType) {
        return type.isAssignableFrom(getType()) && !type.getType().equals(Object.class);
    }
}
Repository: micronaut-projects/micronaut-core
File: http/src/main/java/io/micronaut/http/HttpResponse.java (Java)

Code before:
        return (HttpResponse<B>) HttpMessage.super.setAttribute(name, value);
    }

    /**
     * Return the first value for the given header or null.
     *
     * @param name The name
     * @return The header value
     */
    default @Nullable String header(@Nullable CharSequence name) {
        if (name == null) {
            return null;
        }
        return getHeaders().get(name);
    }

    /**
     * @return The body or null
     */
    default @Nullable B body() {
        return getBody().orElse(null);
    }

    /**
     * @return The HTTP status
     * @deprecated To support custom status codes. Use {@link #code()} instead of {@link #status()} and {@link HttpStatus#getCode()}  and {@link #reason()} instead of {@link #status()} and {@link HttpStatus#getReason()}
     */
    @Deprecated(since = "4.7.2")
    default HttpStatus status() {
        return getStatus();
    }

    /**
     * @return The response status code
     */
    int code();

    /**
     * @return The HTTP status reason phrase
     */
    String reason();

    /**
     * Return an {@link io.micronaut.http.HttpStatus#OK} response with an empty body.
     *
     * @param <T> The response type
     * @return The ok response
     */
    static <T> MutableHttpResponse<T> ok() {
        return HttpResponseFactory.INSTANCE.ok();
    }

Review comment (suggestion):
```suggestion
     * To support custom status codes. Use {@link #code()} instead of {@link #status()} and {@link HttpStatus#getCode()}  and {@link #reason()} instead of {@link #status()} and {@link HttpStatus#getReason()}
```

Code after:
    }

    /**
     * Return the first value for the given header or null.
     *
     * @param name The name
     * @return The header value
     */
    default @Nullable String header(@Nullable CharSequence name) {
        if (name == null) {
            return null;
        }
        return getHeaders().get(name);
    }

    /**
     * @return The body or null
     */
    default @Nullable B body() {
        return getBody().orElse(null);
    }

    /**
     * @return The HTTP status
     * To support custom status codes. Use {@link #code()} instead of {@link #status()} and {@link HttpStatus#getCode()}  and {@link #reason()} instead of {@link #status()} and {@link HttpStatus#getReason()}
     */
    default HttpStatus status() {
        return getStatus();
    }

    /**
     * @return The response status code
     */
    int code();

    /**
     * @return The HTTP status reason phrase
     */
    String reason();

    /**
     * Return an {@link io.micronaut.http.HttpStatus#OK} response with an empty body.
     *
     * @param <T> The response type
     * @return The ok response
     */
    static <T> MutableHttpResponse<T> ok() {
        return HttpResponseFactory.INSTANCE.ok();
    }

    /**
Repository: micronaut-projects/micronaut-core
File: http/src/main/java/io/micronaut/http/context/ServerRequestContext.java (Java)

Code before:
     */
    public static <T> T with(@Nullable HttpRequest<?> request, @NonNull Callable<T> callable) throws Exception {
        try (PropagatedContext.Scope ignore = PropagatedContext.getOrEmpty().plus(new ServerHttpRequestContext(request)).propagate()) {
            return callable.call();
        }
    }

    /**
     * Retrieve the current server request context.
     *
     * @param <T> The body type
     * @return The request context if it is present
     */
    public static <T> Optional<HttpRequest<T>> currentRequest() {
        return ServerHttpRequestContext.find();
    }

    /**
     * Retrieve the current server request context from the given reactor context view.
     *
     * @param context The reactor context view
     * @param <T> The body type
     * @return The request context if it is present
     */
    @SuppressWarnings("unchecked")
    public static <T> Optional<HttpRequest<T>> currentRequest(ContextView context) {
        return ReactorPropagation.findPropagatedContext(context)
            .flatMap(ctx -> ctx.find(ServerHttpRequestContext.class))
            .map(e -> (HttpRequest<T>) e.httpRequest())
            .or(() -> context.getOrEmpty(KEY));
    }
}



Review comment (suggestion):
add `@since` and nullability annotation to the parameter

Code after:
     */
    public static <T> T with(@Nullable HttpRequest<?> request, @NonNull Callable<T> callable) throws Exception {
        try (PropagatedContext.Scope ignore = PropagatedContext.getOrEmpty().plus(new ServerHttpRequestContext(request)).propagate()) {
            return callable.call();
        }
    }

    /**
     * Retrieve the current server request context.
     *
     * @param <T> The body type
     * @return The request context if it is present
     */
    public static <T> Optional<HttpRequest<T>> currentRequest() {
        return ServerHttpRequestContext.find();
    }

    /**
     * Retrieve the current server request context from the given reactor context view.
     *
     * @param context The reactor context view
     * @param <T> The body type
     * @return The request context if it is present
     * @since 4.8.0
     */
    @SuppressWarnings("unchecked")
    @NonNull
    public static <T> Optional<HttpRequest<T>> currentRequest(@NonNull ContextView context) {
        return ReactorPropagation.findPropagatedContext(context)
            .flatMap(ctx -> ctx.find(ServerHttpRequestContext.class))
            .map(e -> (HttpRequest<T>) e.httpRequest())
            .or(() -> context.getOrEmpty(KEY));
    }
}
Repository: micronaut-projects/micronaut-core
File: http/src/main/java/io/micronaut/http/form/FormConfiguration.java (Java)

Code before:
 * https://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 io.micronaut.http.form;

/**
 * Configuration related to forms.
 * @author Sergio del Amo
 * @since 4.7.1
 */
public interface FormConfiguration {
    /**
     *
     * @return default maximum of decoded key value parameters. It defaults to 1024.
     */
    int getMaxDecodedKeyValueParameters();

    /**
     * @return true if the semicolon handle as a normal character, false otherwise.
     */
    boolean isSemicolonIsNormalChar();

}


Review comment (suggestion):
to avoid a breaking change this should be a default method that returns `false`

Code after:
 * https://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 io.micronaut.http.form;

/**
 * Configuration related to forms.
 * @author Sergio del Amo
 * @since 4.7.1
 */
public interface FormConfiguration {
    /**
     *
     * @return default maximum of decoded key value parameters. It defaults to 1024.
     */
    int getMaxDecodedKeyValueParameters();

    /**
     * @return true if the semicolon handle as a normal character, false otherwise.
     */
    default boolean isSemicolonIsNormalChar() {
        return false;
    }

}
Repository: micronaut-projects/micronaut-core
File: inject/src/main/java/io/micronaut/context/event/BeanCreatedEvent.java (Java)

Code before:

    /**
     * @param beanContext    The bean context
     * @param beanDefinition The bean definition
     * @param beanIdentifier The bean identifier
     * @param argument       The {@link Argument} used to create the bean
     * @param bean           The bean
     */
    public BeanCreatedEvent(BeanContext beanContext,
                            BeanDefinition<T> beanDefinition,
                            BeanIdentifier beanIdentifier,
                            Argument<T> argument,
                            T bean) {
        super(beanContext, beanDefinition, bean);
        this.beanIdentifier = beanIdentifier;
        this.argument = argument;
    }

    /**
     * @return The bean identifier used to create the bean
     */
    public BeanIdentifier getBeanIdentifier() {
        return beanIdentifier;
    }

    public Argument<T> getArgument() {
        return argument;
    }
}


Review comment (suggestion):
needs javadoc, but I would call it `getBeanType()`

Code after:
    private final @NonNull Argument<T> beanType;

    public BeanCreatedEvent(BeanContext beanContext,
                            BeanDefinition<T> beanDefinition,
                            BeanIdentifier beanIdentifier,
                            T bean) {
        this(beanContext, beanDefinition, beanIdentifier, beanDefinition.asArgument(), bean);
    }

    /**
     * @param beanContext    The bean context
     * @param beanDefinition The bean definition
     * @param beanIdentifier The bean identifier
     * @param beanType       The {@link Argument} used to create the bean
     * @param bean           The bean
     */
    public BeanCreatedEvent(BeanContext beanContext,
                            BeanDefinition<T> beanDefinition,
                            BeanIdentifier beanIdentifier,
                            @NonNull Argument<T> beanType,
                            T bean) {
        super(beanContext, beanDefinition, bean);
        this.beanIdentifier = beanIdentifier;
        this.beanType = beanType;
    }

    /**
     * @return The bean identifier used to create the bean
     */
    public BeanIdentifier getBeanIdentifier() {
        return beanIdentifier;
    }

    /**
     * @return The argument used to create the bean
     * @since 4.9.0
     */
    @NonNull
    public Argument<T> getBeanType() {
        return beanType;
    }
}
Repository: micronaut-projects/micronaut-core
File: inject/src/main/java/io/micronaut/context/event/BeanCreatedEvent.java (Java)

Code before:
public class BeanCreatedEvent<T> extends BeanEvent<T> {

    private final BeanIdentifier beanIdentifier;

    private final Argument<T> argument;

    /**
     * @param beanContext    The bean context
     * @param beanDefinition The bean definition
     * @param beanIdentifier The bean identifier
     * @param argument       The {@link Argument} used to create the bean
     * @param bean           The bean
     */
    public BeanCreatedEvent(BeanContext beanContext,
                            BeanDefinition<T> beanDefinition,
                            BeanIdentifier beanIdentifier,
                            Argument<T> argument,
                            T bean) {
        super(beanContext, beanDefinition, bean);
        this.beanIdentifier = beanIdentifier;
        this.argument = argument;
    }

    /**
     * @return The bean identifier used to create the bean
     */
    public BeanIdentifier getBeanIdentifier() {
        return beanIdentifier;
    }

    public Argument<T> getArgument() {
        return argument;
    }
}


Review comment (suggestion):
this is a breaking API change. You will need to add a new constructor with the argument (I would call the parameter beanType) and delegate to this new constructor. You can use `beanDefinition.asArgument()` as a default value to maintain compatibility.

Code after:
 */
public class BeanCreatedEvent<T> extends BeanEvent<T> {

    private final BeanIdentifier beanIdentifier;

    private final @NonNull Argument<T> beanType;

    public BeanCreatedEvent(BeanContext beanContext,
                            BeanDefinition<T> beanDefinition,
                            BeanIdentifier beanIdentifier,
                            T bean) {
        this(beanContext, beanDefinition, beanIdentifier, beanDefinition.asArgument(), bean);
    }

    /**
     * @param beanContext    The bean context
     * @param beanDefinition The bean definition
     * @param beanIdentifier The bean identifier
     * @param beanType       The {@link Argument} used to create the bean
     * @param bean           The bean
     */
    public BeanCreatedEvent(BeanContext beanContext,
                            BeanDefinition<T> beanDefinition,
                            BeanIdentifier beanIdentifier,
                            @NonNull Argument<T> beanType,
                            T bean) {
        super(beanContext, beanDefinition, bean);
        this.beanIdentifier = beanIdentifier;
        this.beanType = beanType;
    }

    /**
     * @return The bean identifier used to create the bean
     */
    public BeanIdentifier getBeanIdentifier() {
        return beanIdentifier;
    }

    /**
     * @return The argument used to create the bean
     * @since 4.9.0
     */
    @NonNull
    public Argument<T> getBeanType() {
        return beanType;
    }
}