Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExtensionMethod failed to compile in Eclipse #1695

Closed
daniel-exceed opened this issue May 16, 2018 · 3 comments
Closed

ExtensionMethod failed to compile in Eclipse #1695

daniel-exceed opened this issue May 16, 2018 · 3 comments

Comments

@daniel-exceed
Copy link

using lombok 18 in exlipse oxygen 4.7.3.a, im trying to use this extensions class:
public class ReflectionUtils {
public static String getAnnotationValue(Class<?> clazz, Class<? extends Annotation> anno) {
if (!clazz.isAnnotationPresent(anno)) {
return null;
}

	try {
		return (String)anno.getDeclaredMethod("value").invoke(clazz.getAnnotation(anno));
	} catch (IllegalArgumentException | IllegalAccessException | SecurityException | InvocationTargetException | NoSuchMethodException e) {
		return null;
	}
}

}

in another class like this:
@ExtensionMethod({ReflectionUtils.class})

and call it like this:
public String getField(Class<?> clazz, String field) {
return FieldsMap.get(clazz.getAnnotationValue(Entity.class)).get(field);
}

my eclipse cant compile the entire class claiming:
Internal compiler error: java.lang.ArrayIndexOutOfBoundsException
maven compiles fine.
also, when i use an extension method with only 1 parameter (the object i extend) it compiles fine.

what can be done to make it work?

im attatching the error log of eclipse

lombok error.log

@johnthuss
Copy link

I have the same/simliar problem in Eclipse. It does compile successfully using javac however.

import java.util.Optional;
import lombok.experimental.ExtensionMethod;

class Extensions {
	public static <K, V> Optional<V> getOpt(Map<K, V> map, K key) {
		return Optional.ofNullable(map.get(key));
	}
}
@ExtensionMethod({Extensions.class})
public class Main2 {
	public static void main(String[] args) {
		Map<String, Integer> map = Map.of("key", 1);
		System.out.println(map.getOpt("missing"));
	}
}

Errors occurred during the build.
Errors running builder 'Java Builder' on project 'MyProject'.
java.lang.ArrayIndexOutOfBoundsException

@Maaartinus
Copy link
Contributor

The same for me, using Lombok 1.18.6. and Eclipse
Version: 2018-09 (4.9.0)
Build id: 20180917-1800

I could simplify the code to

public class Extensions {
	public static Optional<String> getOpt(String s, int index) {
		return Optional.ofNullable(null);
	}
}

@ExtensionMethod({Extensions.class})
public class Main2 {
	public static void main(String[] args) {
		final String s = "a";
		System.out.println(s.getOpt(7));
	}
}

The problem disappears when I remove the index argument.

@rzwitserloot
Copy link
Collaborator

Duplicate of #1441

@rzwitserloot rzwitserloot marked this as a duplicate of #1441 Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants