Griffon Upgrade compilation error: mvcGroupInit repetitive method - groovy

I'm upgrading a big 0.3.1 Griffon app into 0.9.4 I'm getting these difficulties:
Controlllers:
I've disabled UI Threading Injection in order to avoid the Compilation BUG issue (see Compilation error: BUG! exception after Griffon project upgrade)
That's how I avoid that compilation error but then some other have appeared:
[griffonc]
[griffonc] C:\maestro\desarrollo\projects\interactionManager\sgmentia-client\griffon-app\controllers\com\nortia\sgmentia\client\select\SelectController.groovy: 53: Repetitive method name/signature for method 'void mvcGroupInit(java.util.Map)' in class 'com.nortia.sgmentia.client.select.SelectController'.
[griffonc] # line 53, column 2.
[griffonc] void mvcGroupInit(Map args) {
[griffonc] ^
[griffonc]
[griffonc] C:\maestro\desarrollo\projects\interactionManager\sgmentia-client\griffon-app\controllers\com\nortia\sgmentia\client\select\SelectController.groovy: -1: Repetitive method name/signature for method 'void mvcGroupInit(java.util.Map)' in class 'com.nortia.sgmentia.client.select.SelectController'.
[griffonc] # line -1, column -1.
It seems as if you were not allowed to overrride this method in a child controller. For example:
class MyCommonController{
...
}
class MyChildController extends MyCommonController{
...
void mvcGroupInit(java.util.Map){}
}
I solved this error in other controllers doing the following refactoring:
class MyCommonController{
...
void mvcGroupInit(java.util.Map args){
initMyCommon(map)
}
abstract void initMyCommon(map)
}
class MyChildController extends MyCommonController{
...
void initMyCommon(map){
//My real init code goes here
}
}
but this controller is more complicated to refactor:
class SelectController extends WindowAdapter implements DocumentController
Is this the real problem? Any ideas?
Thanks in advance.
Ivan.

I've replicated the same settings but can get the application to work properly, at least if all controllers are found inside griffon-app/controllers. However if the base controller is placed in another directory, for example src/main, then you'll get this error.
This is a bug in Griffon that should be fixed. Would you care to post a JIRA ticket at http://jira.codehaus.org/browse/griffon?

Related

Why is getOnBackPressedDispatcher() method unresolved until 'androidx.navigation:navigation-ui' is added as a dependency?

I'm trying to customize onBackPress behaviour of JetPack Navigation. Although I found the solution I'm just curious what's going behind the scenes in the following scenario:
Initial state of my activity is
MyActivity extends androidx.appcompat.app.AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getOnBackPressedDispatcher().addCallback(...); // <--- Method is unresolved
}
}
How come that after I add the following dependency to build.gradle the getOnBackPressedDispatcher() method is being resolved:
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
What's going behind the scenes? Does it have something with the Jetifier? Does it alter the classes based on declared dependencies or something similar?
implementation 'androidx.appcompat:appcompat:1.1.0'
Implement this dependency to its latest version, this will fix the problem.

Rendering GORM classes from Spring Boot

I'm trying to write a simple Spring Boot controller that renders a GORM instance and failing.
Here's a shortened version of my code:
#RestController
#RequestMapping("/user")
class UserController {
#RequestMapping(value='/test', method=GET)
User test() {
return new User(username: 'my test username')
}
}
I get the following error message:
Could not write JSON: No serializer found for class org.springframework.validation.DefaultMessageCodesResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: users.domain.User["errors"]->grails.validation.ValidationErrors["messageCodesResolver"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.validation.DefaultMessageCodesResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: users.domain.User["errors"]->grails.validation.ValidationErrors["messageCodesResolver"])
The error seems to be caused by extra properties injected by GORM. What is the proposed solution for this? Will this eventually be solved in gorm-hibernate4-spring-boot? Should I simply disable SerializationFeature.FAIL_ON_EMPTY_BEANS (I don't have a lot of experience with Jackson so I'm not entirely sure what side effects this may have)? Should I use Jackson's annotations to solve the problem? Any other options?
I've found a way to get rid of the error using this code:
#Component
class ObjectMapperConfiguration implements InitializingBean {
#Autowired
ObjectMapper objectMapper
#Override
void afterPropertiesSet() {
def validationErrorsModule = new SimpleModule()
validationErrorsModule.addSerializer(ValidationErrors, new ErrorsSerializer())
objectMapper.registerModule(validationErrorsModule)
}
}
class ErrorsSerializer extends JsonSerializer<ValidationErrors> {
#Override
void serialize(ValidationErrors errors, JsonGenerator jgen, SerializerProvider provider) {
jgen.writeStartObject()
jgen.writeEndObject()
}
}
Obviously this solution is far from perfect as it simply nukes all validation errors but right now it is good enough for me. I am pretty sure the Spring Boot team will have to address this issue eventually as the GORM objects are also being serialized with some internal Hibernate properties like attached. I'm not accepting this answer as it is not an acceptable solution for most scenarios, it basically just squelches the exception.
This did not work for me.
So I used this instead and the error disappeared.
#JsonIgnoreProperties(["errors"])
I'm using springBootVersion '1.4.1.RELEASE' with gorm & hibernate5:
compile("org.grails:gorm-hibernate5-spring-boot:6.0.3.RELEASE")
I am having to include the following at the top of each domain class in order to use them in a client response (i.e. json serialization using jackson):
#JsonIgnoreProperties(["errors", "metaClass", "dirty", "attached", "dirtyPropertyNames"])
When using springBootVersion '1.3.5.RELEASE' I was able to get away with:
#JsonIgnoreProperties(["errors"])
This is trending in the wrong direction :)

Adding methods to class and use them in other groovy code

I'm very new to Groovy. I have a class where I'm adding methods using metaClass. Here is the code I have for Parser.groovy:
PrivateClass.metaClass.convertDDTToMap { obj,fileLocation ->
}
where PrivateClass is a class coming from a jar. Now in other file named Hack.groovy I have the following code:
class Hack extends PrivateClass
{
//.. code
convertDDTToMap(param,param)
}
when I run Hack.groovy, I get the exception that the method convertDDTToMap is not there.
However Parser.groovy is in the same classpath and it gets compiled. But its not adding the method.
Where I'm making the mistake?
Parser.groovy being compiled only is doing nothing, the code there needs to be called. For example using new Parser().run()

JavaFX IllegalAccessException during FXML load()

I have a dialog window that is invoked by the following code (DialogController is a helper class for using modal dialog windows; it mainly bundles together a controller reference with its window):
void handleServicesEdit(ActionEvent event) throws IOException {
DCServRecEditor sre = DialogController.<DCServRecEditor>loadFXML(
CensusAssistant.RES_FXML_DIALOG_SERVEDIT,
CensusAssistant.RES_STRING_SERVEDIT,
this.getDialog());
sre.setDialogMode(DB.DBEDIT_MODE_EDIT,
tbvService.getItems(),
tbvService.getSelectionModel().getSelectedIndex(),
m_encCal);
sre.showAndWait();
sre.release();
this.updateGUI();
}
I have confirmed that I get an exception during the FXMLLoader.load() method. I have also determined that the error occurs before any code in my initialize() method has a chance to run. Some of the stack trace that I get from load() is here:
java.lang.IllegalAccessException: Class sun.reflect.misc.ReflectUtil
can not access a member of class org.kls.md.censusassistant.DCServRecEditor
with modifiers ""
file:/D:/Documents/NetBeansProjects/CensusAssistant/dist/run1284250063/CensusAssistant.jar!/org/kls/md/censusassistant/fxml/GUIServRecEditor.fxml:13
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:738)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:775)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:180)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:563)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
at org.kls.md.censusassistant.DialogController.loadFXML(DialogController.java:63)
at org.kls.md.censusassistant.DCMainEditor.handleServicesEdit(DCMainEditor.java:330)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Caused by: java.lang.IllegalAccessException: Class sun.reflect.misc.ReflectUtil
can not access a member of class org.kls.md.censusassistant.DCServRecEditor
with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95)
at java.lang.Class.newInstance0(Class.java:368)
at java.lang.Class.newInstance(Class.java:327)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:46)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:731)
... 66 more
My class DCServRecEditor is a subclass of DialogController. It is a pretty normal looking FXML controller class:
class DCServRecEditor extends DialogController {
private int m_dialogMode = DB.DBEDIT_MODE_ADD;
private int m_selServ = -1;
private GregorianCalendar m_cal = null;
#FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
#FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
#FXML // fx:id="ancMatchSelector"
private AnchorPane ancMatchSelector; // Value injected by FXMLLoader
#FXML // fx:id="ancServEditor"
private AnchorPane ancServEditor; // Value injected by FXMLLoader
#FXML // fx:id="ancServRecEditor"
private AnchorPane ancServRecEditor; // Value injected by FXMLLoader
...
}
I have double and triple checked to make sure that there wasn't a named control in the FXML that didn't also have an instance field in the controller class.
All the instance fields are tagged with #FXML.
The name of the controller class in the FXML is the same as my java file and is properly qualified.
The error occurs before initialize() is called, so I don't think it's anything with initialize(), although I have checked to make sure it is also tagged with #FXML.
The skeleton for my controller class was copied and pasted from Scene Builder ... I've gone back and repasted blocks of stuff from Scene Builder to be sure that there wasn't a control I was missing in my java file.
The error message gives me no specifics about the member it is having its problem with, other than to say it has modifiers "".
I went back to my controller class and made all the members with default access public, and I still get the error.
I don't even know where in my class the problem is coming from.
Anyone have any ideas about what is going wrong here?
Yet another embarrassingly simple problem.
I'm surprised someone didn't jump on this by now.
The problem was in my class DCServRecEditor. Note that the class was declared with default access permission.
JavaFX requires that controller classes be made public.
To be fair to myself, Java's error reporting in this situation is abominable and misleading. The stack trace clearly shows that Java is complaining about being unable to access a member of my class, hence my focus on my instance fields and methods. Java really should have complained that it was the class itself that it could not access and not its members.
Had the same issue. In my case controller was at folder that named with uppercase letter. cast to lowercase solve the problem.
I prefer to declare every method and filed public.

Error - None of the constructors found with 'Orchard.Environment.AutofacUtil.DynamicProxy2.ConstructorFinderWrapper'

I have a custom module, Module1. In this module, I am referencing another custom module, Module2. Everything was working fine last week.
I did a fresh re-install of Orchard this morning. Since then, I have been getting this error.
None of the constructors found with 'Orchard.Environment.AutofacUtil.DynamicProxy2.ConstructorFinderWrapper' on type 'Module1' can be invoked with the available services and parameters: Cannot resolve parameter 'Module2' of constructor 'Void .ctor(...)'.
Any idea how to fix this error?
Thanks.
That means that an implementation of some interface could not be found. Several thing can have happened: a module may have failed to compile, or you forgot to make an interface derive from IDependency.
I know the post is quite old now, but just to link any possible mistake that could cause the described problem... here is my mistake.
I simply forgot to enable the referenced module from the dashboard.
Of course that didn't prevent me to add a project reference and module dependency, having the code compiling perfectly .
The point is, my referenced module doesn't contain any content type definition. It is just a module conceived to collect some functionality and common utilities. That's why I forgot to enable it.
Cheers.
You can get this error if you manually enabled your modules.
If so, fix it by deleting App_Data\cache.dat and then recycle the app pool.
I had the same issue. It seems that I referenced the concrete class and not the interface in my constructor.
public OrderService(
IRepository<Order> orderRepository,
ProductService productService,
ProductCategoryService productCategoryService
)
Instead of
public OrderService(
IRepository<Order> orderRepository,
IProductService productService,
IProductCategoryService productCategoryService
)
checklist is:
Interface derive from IDependency
Implementation derive from Interface
Constructor references the Interface
Build All and check if all referenced modules compile
Enable module in Admin panel
example:
public class myController : Controller{
private readonly IMyService _myService;
public myController(
IMyService myService
) {
_myService = myService;
}
}
public interface IMyService : IDependency
{
int GetOne();
}
public class MyService: IMyService
{
public MyService()
{ // init code }
public int GetOne()
{ return 1; }
}

Resources